Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disparity in Objects... #1040

Open
davidcorbin-atmosera opened this issue Oct 16, 2022 · 1 comment
Open

Disparity in Objects... #1040

davidcorbin-atmosera opened this issue Oct 16, 2022 · 1 comment

Comments

@davidcorbin-atmosera
Copy link

I have two chunks of code, running from the same snapshot.

var clrRoots = runTime.Heap.EnumerateRoots(); foreach (IClrRoot root in clrRoots) { /* recursively foreach (ClrReference reference in clrObj.EnumerateReferencesWithFields()) {}
and
` var objs = runTime.Heap.EnumerateObjects().ToList();
foreach (ClrObject obj in objs)
{

The later returns MANY objects that are not revealed by the former.... not understanding why....
`(then again, it is a Sunday afternoon)

@leculver
Copy link
Contributor

Sorry I missed this issue. Feel free to @ me if I don't respond in a timely fashion.

This is expected. There are a few things going on here:

  1. There can be legitimately dead objects on the heap. They will be collected at the next GC.
  2. Some "objects" reported by runtime.Heap.EnumerateObjects() aren't "real" objects, but instead represent free space on the heap. See ClrObject.IsFree.
  3. Some roots may be held onto by stack references which cannot be walked in a crash dump. The CLR GC stackwalker can only walk GC roots on the stack at "Safepoints". There's no guarantee that when a crash dump is taken that we actually were at a GC safepoint for all threads. (Usually it's fairly rare for important objects to be missed this way, but it definitely happens a lot.)
  4. ClrMD may be missing roots, which would be a bug. However, I cannot look into it or make progress without a crash dump or repro to look into it.

As for the last case, ClrMD attempts to replicate the algorithm that the CLR GC uses to find and mark roots...but at times changes to the GC can result in ClrMD's algorithm getting out of sync and missing roots. The only way to fix those cases is for me to have a repro of what's going on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants