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

Memory snapshots analysis #64

Closed
MaheshDevaraj opened this issue Mar 6, 2023 · 2 comments
Closed

Memory snapshots analysis #64

MaheshDevaraj opened this issue Mar 6, 2023 · 2 comments

Comments

@MaheshDevaraj
Copy link

Hi,

I'm trying to use memlab for leak detection, once I run the script I get three snapshots and also some logs on the terminal. Tried to understand what they mean but was not able to. I'm actually trying to drill down on a leak and get to the code that causes the leak. Is there a way to analyse the heaps better and get to the exact code that causes the leaks?

Thanks,
Mahesh

@JacksonGL
Copy link
Member

Hi @MaheshDevaraj, please check out the documentation website, specifically the tutorial page which could be useful in understanding the terminal output. Here's the link: https://facebook.github.io/memlab/docs/guides/guides-detached-dom

The memory leak trace produced by MemLab is a reference chain that starts from the GC (garbage collector) root and ends at the leaked object. This reference chain is similar to the retainer path in Chrome DevTool, and there are various online resources available to help you debug a retainer path.

Although the V8 heap snapshot captures limited source information, there are some effective ways to narrow down the scope and identify the relevant code. One way is to use memlab view-heap --node-id <LEAKED_OBJECT_ID> to obtain more information about the leak trace. To locate the code responsible for creating an object on the trace, search for the intersection of object property names. Alternatively, to locate the code associated with a closure, search for the intersection of variable names in the closure scope.

It's recommended to run the web application being tested with non-minified JS code.

@MaheshDevaraj
Copy link
Author

Hi @JacksonGL , Thanks for the updates.
I tried following the above suggestions, In my case in the memlab logs I don't see any variable (leakedObjects from the https://facebook.github.io/memlab/docs/guides/guides-detached-dom , for example). I only see random numbers being shown and from this I'm not able to narrow down to the code that causes the leaks. I also used memlab view-heap --node-id <LEAKED_OBJECT_ID> and was not able to get any useful informations.

While using Chrome Dev tools memory profile, I'm able to see a link to the code that causes the leak. Can you guide me here? Not sure if I've missed something while using memlab.

Memlab logs from my application:-
MemLab found 7 leak(s)

--Similar leaks in this run: 13--
--Retained size of leaked objects: 105.4KB--
[] (synthetic) @1 [5.3MB]
--2 (shortcut)---> [Window / http://localhost:8000] (object) @9823 [48.6KB]
--require (property)---> [requirejs] (closure) @69911 [3.1KB]
--s (property)---> [Object] (object) @69913 [212 bytes]
--contexts (property)---> [Object] (object) @54171 [96 bytes]
--_ (property)---> [Object] (object) @54173 [2.3KB]
--defined (property)---> [Object] (object) @53929 [37.8KB]
--preact/compat (property)---> [Object] (object) @54089 [9.3KB]
--useTransition (property)---> [K] (closure) @137041 [68 bytes]
--context (internal)---> [] (object) @122325 [116.3KB]
--U (variable)---> [p] (object) @227695 [107.6KB]
--__P (property)---> [Detached HTMLElement] (native) @212991 [105.4KB]
--11 (element)---> [Detached InternalNode] (native) @262836032 [228 bytes]
--2 (element)---> [Detached DOMTokenList] (native) @213075 [84 bytes]

--Similar leaks in this run: 32--
--Retained size of leaked objects: 5.4KB--
[Window] (native) @41625 [52.8KB]
--4 (element)---> [HTMLDocument] (native) @41611 [10.7KB]
--jQuery361067752674121521841 (property)---> [Object] (object) @79307 [836 bytes]
--events (property)---> [Object] (object) @130275 [584 bytes]
--touchcancel (property)---> [Array] (object) @130523 [180 bytes]
--0 (element)---> [Object] (object) @130539 [68 bytes]
--handler (property)---> [native_bind] (closure) @130503 [136 bytes]
--bound_this (internal)---> [constructor] (object) @129375 [8.9KB]
--m_preActiveItem (property)---> [jQuery.fn.init] (object) @242125 [192 bytes]
--0 (element)---> [Detached HTMLLIElement] (native) @212863 [1.3KB]
--8 (element)---> [Detached HTMLAnchorElement] (native) @213121 [1.2KB]
--5 (element)---> [Detached DOMTokenList] (native) @274847456 [56 bytes]

--Similar leaks in this run: 3--
--Retained size of leaked objects: 292 bytes--
[(GC roots)] (synthetic) @3 [598.2KB]
--13 (element)---> [(Global handles)] (synthetic) @29 [1KB]
--10 / DevTools console (internal)---> [Detached HTMLSpanElement] (native) @40985 [688 bytes]
--3 (element)---> [Detached InternalNode] (native) @75016864 [548 bytes]
--6 (element)---> [Detached InternalNode] (native) @75057344 [232 bytes]
--1 (element)---> [Detached NodeList] (native) @213115 [84 bytes]

--Similar leaks in this run: 1--
--Retained size of leaked objects: 272 bytes--
[] (synthetic) @1 [5.3MB]
--2 (shortcut)---> [Window / http://localhost:8000] (object) @9823 [48.6KB]
--oj (property)---> [Object] (object) @53949 [5.8KB]
--CompositeTemplateRenderer (property)---> [Object] (object) @99535 [836 bytes]
--_BINDING_CONTEXT (property)---> [ko.bindingContext] (object) @131325 [68 bytes]
--ko (property)---> [Object] (object) @41837 [38.8KB]
--tasks (property)---> [Object] (object) @123809 [1.4KB]
--scheduler (property)---> [] (closure) @192441 [548 bytes]
--context (internal)---> [] (object) @192757 [480 bytes]
--div (variable)---> [Detached HTMLDivElement] (native) @41691 [412 bytes]
--3 (element)---> [Detached InternalNode] (native) @274838656 [272 bytes]
--1 (element)---> [Detached InternalNode] (native) @274900896 [272 bytes]
--1 (element)---> [Detached InternalNode] (native) @274849216 [272 bytes]
--1 (element)---> [Detached MutationObserverRegistration] (native) @262804992 [272 bytes]

--Similar leaks in this run: 3--
--Retained size of leaked objects: 248 bytes--
[Window] (native) @41625 [52.8KB]
--4 (element)---> [HTMLDocument] (native) @41611 [10.7KB]
--10 (element)---> [Range] (native) @56703552 [96 bytes]
--2 (element)---> [HTMLUListElement] (native) @41341 [6.3KB]
--8 (element)---> [HTMLDivElement] (native) @41373 [472 bytes]
--6 (element)---> [HTMLDivElement] (native) @41345 [1.3KB]
--7 (element)---> [HTMLElement] (native) @41083 [14.4KB]
--13 (element)---> [HTMLDivElement] (native) @41085 [664 bytes]
--9 (element)---> [HTMLDivElement] (native) @41567 [752 bytes]
--8 (element)---> [Text] (native) @41031 [124 bytes]
--4 (element)---> [HTMLElement] (native) @41039 [700 bytes]
--6 (element)---> [Text] (native) @41383 [124 bytes]
--4 (element)---> [HTMLDivElement] (native) @41381 [456 bytes]
--7 (element)---> [Text] (native) @41421 [124 bytes]
--4 (element)---> [HTMLUListElement] (native) @41419 [452 bytes]
--6 (element)---> [Text] (native) @41441 [124 bytes]
--4 (element)---> [Comment] (native) @41121 [124 bytes]
--5 (element)---> [Comment] (native) @41125 [3.8KB]
--_templateNode (property)---> [Detached HTMLTemplateElement] (native) @41115 [1.7KB]
--6 (element)---> [Detached DocumentFragment] (native) @41135 [1.1KB]
--5 (element)---> [Detached Text] (native) @75038304 [96 bytes]
--2 (element)---> [Detached HTMLLIElement] (native) @74974464 [808 bytes]
--2 (element)---> [Detached Text] (native) @74994624 [96 bytes]
--2 (element)---> [Detached HTMLAnchorElement] (native) @75012704 [504 bytes]
--1 (element)---> [Detached DOMTokenList] (native) @274834336 [56 bytes]

--Similar leaks in this run: 1--
--Retained size of leaked objects: 56 bytes--
[Window] (native) @41625 [52.8KB]
--4 (element)---> [HTMLDocument] (native) @41611 [10.7KB]
--12 (element)---> [HTMLHtmlElement] (native) @41515 [7.4KB]
--6 (element)---> [HTMLBodyElement] (native) @41589 [312 bytes]
--5 (element)---> [Text] (native) @75010304 [96 bytes]
--2 (element)---> [Comment] (native) @75009984 [96 bytes]
--3 (element)---> [Text] (native) @262852832 [96 bytes]
--3 (element)---> [HTMLScriptElement] (native) @40819 [3KB]
--__ko__1679020612580 (property)---> [Object] (object) @131615 [2.5KB]
--4__ko__1679020612580 (property)---> [Object] (object) @131629 [2.4KB]
--containerData (property)---> [Detached HTMLDivElement] (native) @40829 [2.2KB]
--4 (element)---> [Detached Text] (native) @40825 [124 bytes]
--4 (element)---> [Detached HTMLLIElement] (native) @40823 [1.8KB]
--3 (element)---> [Detached HTMLAnchorElement] (native) @40835 [372 bytes]
--3 (element)---> [Detached DOMTokenList] (native) @274896416 [56 bytes]

--Similar leaks in this run: 1--
--Retained size of leaked objects: 48 bytes--
[] (synthetic) @1 [5.3MB]
--2 (shortcut)---> [Window / http://localhost:8000] (object) @9823 [48.6KB]
--$ (property)---> [jQuery] (closure) @50567 [26.1KB]
--support (property)---> [Object] (object) @93481 [1.2KB]
--reliableTrDimensions (property)---> [reliableTrDimensions] (closure) @192215 [68 bytes]
--context (internal)---> [] (object) @193043 [640 bytes]
--div (variable)---> [Detached HTMLDivElement] (native) @41553 [188 bytes]
--3 (element)---> [Detached InternalNode] (native) @262884032 [48 bytes]
--1 (element)---> [Detached CSSStyleDeclaration] (native) @274845856 [48 bytes]

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