[KONQ_E_1_0_BRANCH] Javascript memory leak partially resolved
Luciano Montanaro
konq-e@mail.kde.org
Wed, 15 Jan 2003 16:41:33 +0100
--Boundary-00=_tEYJ+yjT5ERvFBV
Content-Type: Text/Plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
Content-Description: clearsigned data
Content-Disposition: inline
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Some time ago, there was a discussion about a snippet of javascript similar to
this one:
//------------
// this script demonstrates the memory leak bug.
// The bigstr string should eat around
// 10*2^18 ~ 2.5MB, rally eats ~ 5MB; 10*2^20 ~ 10MB, eats ~ 20MB
var bigstr = "0123456789";
for (i = 0; i < 20; i++) {
bigstr += bigstr;
}
debug("String length = " + bigstr.length);
//------------
That allocated twice the memory it really needs.
I searched the kde-cvs list for leak related fixes in CVS, and found
one change that could solve the problem. The change is pretty simple and
seemingli innocuous, but running the above program I get
49 objects still allocated at the end of the program, and a core file
of ~1.5M against one of 40M, so the patch seems effective.
The remaining allocated objects seem to be allocated during the GlobalObject
initialization.
I'll look for those later.
I'd like advice on this patch: do you think it's useful enough to ask for
inclusion on the KDE2.2 branch for use by kdenox?
Luciano
- --
Luciano Montanaro// My public GPG key can be /"\ ASCII RIBBON
\X/ found at wwwkeys.pgp.net \ / CAMPAIGN
X AGAINST HTML
/ \ MAIL
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iD8DBQE+JYEzaeOY6B53J4URAjICAKChADBokK7faOt31NtraJNZbxVukACfdFHI
DB5HirlkFthLteOXlY/xEqA=
=o1Yj
-----END PGP SIGNATURE-----
--Boundary-00=_tEYJ+yjT5ERvFBV
Content-Type: text/x-diff;
charset="us-ascii";
name="internal-leak.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="internal-leak.patch"
Index: internal.cpp
===================================================================
RCS file: /home/cvs/cvsroot/Konq-Embed/konq-embed/kdesrc/kjs/internal.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- internal.cpp 28 Jul 2001 15:32:15 -0000 1.1
+++ internal.cpp 15 Jan 2003 11:00:10 -0000 1.2
@@ -200,27 +200,27 @@
}
ReferenceImp::ReferenceImp(const KJSO& b, const UString& p)
- : base(b), prop(p)
+ : base(b.imp()), prop(p)
{
}
void ReferenceImp::mark(Imp*)
{
Imp::mark();
- Imp *im = base.imp();
+ Imp *im = base;
if (im && !im->marked())
im->mark();
}
CompletionImp::CompletionImp(Compl c, const KJSO& v, const UString& t)
- : comp(c), val(v), tar(t)
+ : comp(c), val(v.imp()), tar(t)
{
}
void CompletionImp::mark(Imp*)
{
Imp::mark();
- Imp *im = val.imp();
+ Imp *im = val;
if (im && !im->marked())
im->mark();
}
@@ -529,6 +529,8 @@
exVal->mark();
if (retVal && !retVal->marked())
retVal->mark();
+ if (glob.imp())
+ glob.imp()->mark();
UndefinedImp::staticUndefined->mark();
NullImp::staticNull->mark();
BooleanImp::staticTrue->mark();
Index: internal.h
===================================================================
RCS file: /home/cvs/cvsroot/Konq-Embed/konq-embed/kdesrc/kjs/internal.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- internal.h 27 Jul 2001 18:13:03 -0000 1.1
+++ internal.h 15 Jan 2003 11:00:10 -0000 1.2
@@ -135,13 +135,13 @@
ReferenceImp(const KJSO& b, const UString& p);
virtual ~ReferenceImp() { }
virtual void mark(Imp*);
- KJSO getBase() const { return base; }
+ KJSO getBase() const { return KJSO(base); }
UString getPropertyName() const { return prop; }
virtual const TypeInfo* typeInfo() const { return &info; }
static const TypeInfo info;
private:
- KJSO base;
+ Imp *base;
UString prop;
};
@@ -151,14 +151,14 @@
virtual ~CompletionImp() { }
virtual void mark(Imp*);
Compl completion() const { return comp; }
- KJSO value() const { return val; }
+ KJSO value() const { return KJSO(val); }
UString target() const { return tar; }
virtual const TypeInfo* typeInfo() const { return &info; }
static const TypeInfo info;
private:
Compl comp;
- KJSO val;
+ Imp *val;
UString tar;
};
--Boundary-00=_tEYJ+yjT5ERvFBV--