Severe JS memory leak - can someone confirm?

Simon Hausmann konq-e@mail.kde.org
Thu, 17 Oct 2002 09:23:44 +0200


On Tue, Oct 15, 2002 at 06:58:49PM +0200, Paul Chitescu wrote:
> Hello!
> 
> Can someone confirm the severe Javascript memory leak I've found?
> 
> In the process of implementing special host Javascript objects I found that
> most (or all?) of the global objects never get destroyed! As I suspected a
> bug in my implementation I tried with a normal Javascript string which
> didn't got destroyed either.
> 
> Code to reproduce bug:
> 
> <html><body>
> <script language="Javascript"><!--
> var bigstr="0123456789";
> // 10*2^18 ~ 2.5MB, rally eats ~ 5MB; 10*2^20 ~ 10MB, eats ~ 20MB
> for (i=0; i<18; i++) bigstr+=bigstr;
> document.write("String length = ",bigstr.length);
> // --></script>
> </body></html>
> 
> Write the code in a .html file and load it in konq-e. Locate the process in
> /proc and watch the VmData (or use the "top" program). Press F5 several
> times so the document is cleared and reloaded several times. If VmData keeps
> growing with about 5MB at every reload the bug is confirmed.
> 
> The full Desktop Konqueror works as expected, the memory is used only while
> the page is displayed and does not increase when reloading.
> 
> May this be related to the "QObject::connect() No such signal
> QObject::cleared()' debug message? I think this is caused by the fact we
> don't use a proper KHTMLView. The KHTMLPart::clear() gets called but maybe
> there are some references left from somewhere else.

I think it's unrelated to khtmlview. The JS engine in kde2 had its
fair share of problems with the garbage collector, as far as I know.
It works MUCH better in the kde3 codebase.

What does everyone think about switching to QT3 and KDE3 khtml/kjs
as codebase?

Simon