How to find non-destroyed but GC'ed Javascript objects in Chrome?
Asked Answered
C

1

10

I have an application with some objects (of type BaseTexture) on which an explicit destroy function should be called when they aren't of any more use. Otherwise they might leak some memory. This should be done before they are garbage collected (and obviously only can be done then), but it doesn't always happen.

In Java I would detect and log this using finalize, but such a thing does not exist in Javascript.

Can I detect this in Chrome (or in another browser)? I don't really care if it's buggy, requires flags, can only log a simple message, etc, as long as it works during development. The fact that a BaseTexture has been destroyed can be retrieved from its source property.

Concoction answered 6/7, 2015 at 15:35 Comment(0)
S
3

If the purpose of this is to check for memory leaks, then why cant you just run a chrome profile instead?

The Object allocation tracker can be used to find memory leaks at runtime, also the heap profiler can analyze memory graphs and compare snapshots to discover what objects are not being cleaned up by the gc.

Also the timeline memory view can help identify if you are forcing garbage collection too often by allocating too often (if thats of interest)

For more info, see: https://developer.chrome.com/devtools/docs/javascript-memory-profiling

Also not sure if its helpful, but if you want to look at memory stats then you can enable memory info in chrome by running with the --enable-memory-info param, then you have access to window vars:

window.performance.memory.jsHeapSizeLimit
window.performance.memory.totalJSHeapSize
window.performance.memory.usedJSHeapSize
Sirois answered 9/10, 2015 at 18:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.