[whatwg] Low Memory Event

Boris Zbarsky bzbarsky at MIT.EDU
Fri Dec 31 20:01:42 PST 2010


On 12/31/10 7:35 PM, Charles Pritchard wrote:
> If I were to receive an event, letting me know a low memory condition
> exists

In many cases the only way a browser can determine that such a condition 
exists is by trying to allocate memory and having the allocation fail. 
At which point... it's out of memory.  It doesn't have memory to 
allocate the event object, much less to run your script.

There are various ways to try to work around this by trying to 
pre-reserve a memory pool, but they're not very reliable.  I suggest 
reading the pretty extensive discussions on this topic in Mozilla's 
bugzilla and on the various Mozilla mailing lists over the last several 
years.

> I'd drop most of my buffers
> immediately, allowing for the machine and my application to carry on
> normally, a little while longer.

"drop most of my buffers" means you stop referencing them.  They don't 
get deallocated until garbage collection happens.  Garbage collection 
can require memory to perform.  In the case of Gecko, collecting 
canvases in fact requires a cycle-collection algorithm to run, which has 
to build a graph representing the current reference graph.  It's a 
fairly memory-hungry algorithm.

So by the time you're out of memory, doing this is too late.  It won't work.

 > The downside is that there'd be another word in the
> large vocabulary of HTML/DOM events.

And significantly greater implementation complexity for browsers if they 
try to make it work.  And it still wouldn't work.

> The usefulness has already been proven by iOS applications. We can work
> with low memory events there.

iOS may well provide useful low memory notifications to applications. 
Other OSes do not.  You find out about low memory when your allocation 
fails if you're lucky or when the kernel sends you a SIGKILL (Linux, I'm 
looking at you).

> I'd like to be able to listen for them on the desktop as well.

Then get desktop OS vendors to give applications a way to detect low 
memory reliably.

-Boris



More information about the whatwg mailing list