How to handle Out-of-Memory in Konqueror?

Guillaume Laurent glaurent at telegraph-road.org
Wed Feb 25 17:51:40 GMT 2004


On Wednesday 25 February 2004 14:47, Stefan Taferner wrote:
>
> What I've meant: traditionally in Unix programs one does not care about out
> of memory conditions.

It's generally true, but sendmail and xemacs are two notable exceptions. I'm 
sure there are many others.

> > I just checked the behavior of konqueror if I do "ulimit -v 40000", i.e.
> > limiting to 40 MB virtual space. This is enough for KDE libs and khtml
> > part. Result: It *always* crashes at arbitrary points with different
> > backtraces while browsing. Obviously, konqueror never handled this
> > gracefully.
>
> Yes, that's what I wanted to say what will happen. If you try to catch it,
> you have to catch it everywhere.

No, the whole point of exceptions is that you do not have to "catch them 
everywhere". It can be true in some cases, but such system-level exceptions 
are supposed to be caught at a single point the highest level (the program's 
event loop, generally), where the handler will exit gracefully.

In short, this is silly :

try { Foo* foo = new Foo(); } catch(OutOfMemory) { do_something(); }
...
try { Bar* bar = new Bar(); } catch(OutOfMemory) { do_something_else(); }
...
etc...

because in essence it defeats the purpose of exceptions and turn them into 
error codes. This is the right way :

try { myApplication->run() } catch (OutOfMemory) { exit_gracefully(); }

*BUT*, since Qt and KDE are almost always compiled without exception support, 
you can't do the correct thing and you'd have to do the silly thing. 
Hopefully with exception support improving in gcc3, this constraint will 
eventually go away.

-- 
				Guillaume
				http://www.telegraph-road.org




More information about the kde-core-devel mailing list