[webkit-dev] Out-of-memory handling

Darin Adler darin at apple.com
Mon Dec 8 10:37:38 PST 2008

On Dec 8, 2008, at 8:21 AM, Kelemen Balázs wrote:

> A tempting approach would be using exception handling. E.g., what if  
> we could catch a bad_alloc exception?

To use exception handling you'd probably have to change all the WebKit  
code to do cleanup when an exception is propagating. Otherwise,  
exiting an arbitrary function half way through could leave data  
structures in an inconsistent state.

Fixing this is a large project, almost certainly impractical.

> Would there be any way to simply force WebKit from the browser to  
> "shutdown" itself? When I say shutdown, I mean exiting in an elegant  
> way, e.g., we could save history and other important information to  
> disk (so that when the browser restarts, some info does not get lost).

Sure, you could do that if you make sure that the "important  
information" is stored in data structures that have some sort of  
integrity guarantee, which are not manipulated directly by the WebCore/ 
WebKit code. And make sure the code that writes those data structures  
can function without allocating additional memory.

But I don't think there's any real advantage to using exception  
handling for this. You could have a function called when out of memory  
that does this work.

Another approach is to save history and other important information as  
you go. So if you run out of memory there's nothing that needs to be  

     -- Darin

More information about the webkit-dev mailing list