Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unexplained growth in chrome private memory

I am in the process of profiling a javascript library I wrote, looking for memory leaks. The library provides an API and service to a back-end. It does not do any html or dom manipulation. It does not load any resources (images, etc). The only thing it does is make xhr requests (using jquery), including one long poll, and it passes and receives data to and from the UI via events (using a Backbone event bus).

I have tested this library running it overnight for 16 hours. The page that loads it does nothing but load the library and sends a login request to start the service. There were no html, css, or other dom changes over the course of the test.

All that happened over the course of the test was the library sent a heartbeat (xhr request) to the server every 15 seconds, and received a heartbeat via the long poll every 30 seconds.

I ran the test with the chrome task manager open, and with the chrome debugger open, in order to force GCs from the timeline.

At the start of the tests, after I forced an initial GC - these were the stats from the chrome task manager: Memory - 11.7mb

Javascript memory - 6.9 mb / 2.6mb live

Shared memory - 21.4 mb

Private memory 19mb

After 16hrs I forced a GC - these were the new stats: Memory - 53.8mb

Javascript memory - 6.9 mb / 2.8mb live

Shared memory - 21.7 mb

Private memory 60.9mb

As you can see the JS heap grew by only 200k.

Private memory grew by 42mb!

Can anyone provide possible explanations of what caused the private memory growth? Does having the chrome debugger open cause or affect the memory growth?

One other thought I had is that forcing the GC from the timeline debugger only reclaimed memory from the JS heap - so other memory was not reclaimed. Therefore this may not be a 'leak' per se, as it may eventually be collected - though I'm not sure how to confirm this. Especially without knowing what this memory represents.

Lastly, I did read that xhr results are also stored in private memory. Does anyone know if this is true? If so, the app did perform approx 5700 xhr requests over this timeframe. If most of the 42mb was due to this, that would mean approx 7k was allocated - which seems high, considering the payloads were very small. If this is the case; when would this memory be released, is there anything I can do to cause it to be released, and would having the chrome debugger open impact this?

like image 786
Douglas Miller Avatar asked Oct 04 '22 23:10

Douglas Miller


1 Answers

I was unable to find information on precisely when and what goes to private memory versus javascript memory. However I can answer this: "would having the chrome debugger open impact this" ... YES.

Having the developer tools opened causes the browser to gather/retain/display a lot more information about each and every XHR that is being made. This data is not gathered/retained when the developer tools are closed (as most know since it is sometimes bloody annoying when you open the dev tools to late and it missed that one request you cared about).

You can open the dev tools, trigger the GC, then close the dev tools, opening them only again to trigger the GC when you want to take the metric. Also you can use this sucker chrome://memory-redirect/ to keep track of the growth without opening the dev tools.

like image 74
Nick Sharp Avatar answered Oct 13 '22 10:10

Nick Sharp