--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
Chromium Developers mailing list: chromi...@chromium.org
On Mon, Jan 30, 2012 at 02:55, Ramki Gaddipati <ramki...@gmail.com> wrote:
> Thanks Mikhail.
>
> It is common to observe in snapshots of my app that GC Root (Global
> handles) is holding on to more than 25000 HTML Elements.
> Also I notice several thousands of strings, all tracing no retaining
> path to the window but the GC root.
>
That's normal. When you access a DOM node from your JS code, a wrapper
object is created in JS heap, and a weak global handle is created for
the native object. Those handles are harmless. It's about the same
story with strings. Some of them are residing in browser's memory, and
V8 only references them.
What you should look at is whether your app creates leaks detached DOM
trees -- this is what upcoming DOM counters are for.
> The app is expected to run for several days at a stretch. With time
> the memory usage is shooting up so much that it leaves no option but
> to restart the app (usually in two days). In the heap snapshot I see a
> really large number of strings, arrays, objects and closures. Most of
> them don't have any retaining path from the window.
>
What happens if you press the "Collect garbage" button on Timeline panel?
> Can you help me understand when an object gets added to and deleted
> from Global handles?
> For example, if I use XMLHTTPRequest, which is a native object and
> register event handlers, I assume the event handlers are added to
> Global handles. But when do they become available for garbage
> collection?
>
That really depends on the nature of the object. For the XHR object
the agreement should be as described here:
http://www.w3.org/TR/XMLHttpRequest/#garbage-collection
> Chromium Developers mailing list: chromi...@chromium.org
The spec says: "... its state is HEADERS_RECEIVED, or its state is
LOADING, and ... has one or more event listeners ...".
This is a reasonable condition. If your code is interested in the
result, and the activity is still going, the XHR object will not be
garbage-collected, even if it's not referenced.
When loading has finished, it doesn't matter whether the object has
event listeners, or not. It will be GCed once you erase all references
to it.
What you might need to do is to make sure to call the 'abort()' method
if you are not sure whether the object has finished its activity.
>
> Also if a I register certain event handlers on DOM node and if the DOM
> node is detached and is not referred to by any object in the
> Javascript world (including the event handler), will the DOM node be
> garbage collected?
>
Sure. Consider this simple example:
<html>
<head>
<title>Event handler test</title>
<script type="text/javascript">
function createWrapper() {
nodeWrapper = document.getElementById("a");
nodeWrapper.onclick = detachNode;
}
function detachNode() {
document.body.removeChild(nodeWrapper);
nodeWrapper = null;
}
</script>
</head>
<body onload="createWrapper()">
<input id="a" type="button" value="A" />
</body>
</html>
If you take a heap snapshot before pressing a button, then after, and
then compare these two snapshots, you'll notice a deleted
"HTMLInputElement" in the diff.
> Chromium Developers mailing list: chromi...@chromium.org