Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are items with no connection to a garbage collection root part of a heap snapshot in Chrome?

This heap snapshot output was taken after clicking the trash can on the "Timeline" tab to force a garbage collection.

Summary View Containment View

On the left hand panel, I see that the heap snapshot totals 203MB.

When I'm in the summary view, I can see that 203MB broken down by the various constructors of the objects present. I notice that several of the items in the list with the largest retained sizes have no distance from any garbage collection root (just shows a "–").

When I switch to the containment view, I see that the retained sizes of items listed there totals only a few MB.

If I forced a garbage collect before taking the heap snapshot, shouldn't all of those objects with no connection to a garbage collection root no longer be part of the heap?

like image 601
timehat Avatar asked Dec 17 '25 05:12

timehat


1 Answers

The distance is calculated from a Window object rather than a GC root. Thus a dash means that none of the retaining paths go through a Window.

It's hard to say what is retaining objects from the screenshot. Try selecting an object you concern about and check its retaining path at the bottom view.

Often objects are getting kept in the heap because of being logged into the console which keeps a reference. There might be other cases.

like image 135
alph Avatar answered Dec 19 '25 22:12

alph



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!