New issue
Advanced search Search tips
Starred by 3 users

Issue metadata

Status: Duplicate
Merged: issue 870352
Owner:
Closed: Sep 25
Components:
EstimatedDays: ----
NextAction: ----
OS: Windows
Pri: 2
Type: Bug



Sign in to add a comment
link

Issue 852746: Optimize handling of objects retained from devTools only

Reported by jeromin....@gmail.com, Jun 14 2018

Issue description

UserAgent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3452.0 Safari/537.36

Steps to reproduce the problem:
1. use a web application which has many/cyclic eval calls
2. try to find a memory leak in it with the heap snapshot tool of the devTools

https://github.com/nodejs/node/issues/19733 is probably the same

What is the expected behavior?
Only stuff should be shown which is used by the app itself

What went wrong?
All eval strings of the past are kept in the heap and therefor shown. 
I see many possible solutions:

* Filter/hide all objects in the heap snapshot view which have only the devTools debugger as the retainer (not sure this is possible).

* Add an devTools settings so the source of the evalExpression is not saved anymore. The call stack at this function would be empty.

* Release references to all resources (for example eval sources)  "when not needed" anymore. This is probably tricky, as it is not easy to detect that the developer will not be able to look at a eval source anymore.

Did this work before? N/A 

Chrome version: 69.0.3452.0  Channel: dev
OS Version: 6.1 (Windows 7, Windows Server 2008 R2)
Flash Version:
 

Comment 1 by jeromin....@gmail.com, Jun 14 2018

I attached a minimal example.
evalSource_in_devtools.html
376 bytes View Download

Comment 2 by krajshree@chromium.org, Jun 14 2018

Labels: Needs-Triage-M69

Comment 3 by l...@chromium.org, Jun 14 2018

Owner: kozy@chromium.org
Status: Assigned (was: Unconfirmed)

Comment 4 by tobias.k...@googlemail.com, Sep 3

I run into the same issue while trying to investigate memory leaks in webpack. webpack dynamically compiles generated code (with `new Function`), which causes these leaks when devtools are attached.

I was able to reproduce this with

    (function test() {
        new Function();
        setImmediate(test);
    }());

I would propose that the devtools only hold a weak reference the functions.
That should not cause any issues since functions can't be called when not referenced. Maybe only hold a strong reference when breakpoints are set in the source or the source is open in the Sources panel.

In production this issue should not be critical, because devtools are rarely attached, but it makes investigating (real) memory leak much more difficult as much noise is generated by the devtools.

I attached an image of this leak in a real application.
memory leak.PNG
176 KB View Download

Comment 5 by michael....@uni-due.de, Sep 20

I have similar problems debugging a very huge application which is supposed to run 24/7: As long as the DevTools are open the used memory is rising very fast due to eval(). 
Maybe it would make sense to have a “Clear DevTools” button. Similar to the “Clear console” button.
Or have a cleanup after closing the DevTools (Snapshots are delete as well after closing).

Additionally, I’d like to link an other issue: https://bugs.chromium.org/p/chromium/issues/detail?id=870352 . Like suggested by kozy: the problems may be related and the right solution (e.g. if the object are not just filtered/hided or cleanup after closing) here could also help with the linked bug.

Comment 6 by kozy@chromium.org, Sep 25

Mergedinto: 870352
Status: Duplicate (was: Assigned)
These both issues have the same root, DevTools store hard reference to all scripts to be able to request it content in future.

Sign in to add a comment