Is there a way to get notified when the browser triggers garbage collection? (Or is finished with collecting garbage)
In the process of developing a webapp, it would be quite handy to get notified when the used heap thresholded a certain value, or proportion, after garbage collection.
Simple answer: It depends on the browser's implementation (with current browsers: NO)
First, memory management isn't part of the JavaScript, it's part of the environment (e.g, browser). Since JavaScript runs on VM created by the browser so like other languages it's platform's task not the language itself. Like Java, JVM decides when to run GC, not Java.
Second, about the notification part, It depends on the browser's implementation. Currently, no famous browser provides such functionality to notify user when GC has triggered and when it's finished. However, memory information can be acquired manually, during debugging, using browser's profiler.
However, Info about its memory can be find, during program execution, in window
object.
You can implement your callback function to acquire knowledge about memory usage using window.performance.memory
object whenever you wanted.
In chrome it' provide updated info if you run chrome with --enable-memory-info
switch.
For Chrome More info can be found here: http://blog.chromium.org/2011/05/chrome-developer-tools-put-javascript.html