3 ms·
In most cases this event wouldn't be too useful because: a) More often than not, these errors are caused by objects which could not be removed by the Garbage C
by se85 14y ago
In most cases this event wouldn't be too useful because:
a) More often than not, these errors are caused by objects which could not be removed by the Garbage Collector because they are still within an active scope, so by definition the objects consuming all the memory are still very much in use. A better understanding of JavaScript would go much further than an onmemory event to try and monkey patch the memory leaks away.
b) There's no guarantee that you could clean out the objects before the VM crashed anyway, because the event fired would be asynchronous, and the JavaScript isn't going to halt everything else and wait for your code to run.
I know there is plenty more reasons as well when you get deeper into the GC collection side of things - but I won't go there without narrowing it down to a particular javascript platform first ;-)
Javascript being able to hook into things like this so you know more about memory usage and stuff would be great, but there is a number of technical hurdles to overcome, and I doubt that most Javascript developers would care of its existence if all the work was done to make it so.