Code is leaking and I can't figure out why

T

Thomas 'PointedEars' Lahn

Doug said:
The code in question is available from

http://mozilla.pastebin.com/596645

Any help would be extremly appreciated,

What are you paying for debugging these almost 1000 lines of
uncommented, ill-indented, inefficient source code?
because I've spent many hours on trying to figure this out!!

Spend more hours, or rewrite it from scratch, unless you are
going to pay me for this.


PointedEars
 
D

Doug Wright

You're complaining about the amount of code, but want a lengthier
version (with comments)?

The original code is commented, but I removed them from the paste
because it is indeed a lot of code for someone to look over. The amount
of memory leaking implies that there's something fundamentally wrong
about my approach to constructing the returned string - the ins and
outs of the returned result aren't relevant.

I hadn't realised the code came out so ill-formatted - my source is all
neatly idented in my editor - sorry about that.

As for ineffiency - are you referring to the repeated occurences of
'skinElement[skinElementID]' instead of replacing them with something
like 'var element = skinElement[skinElementID]', and then using
'element', or is there a better approach than switch/case?
 
T

Thomas 'PointedEars' Lahn

Doug said:
You're complaining about the amount of code, but want a lengthier
version (with comments)?

Yes, I do. Quantity is not quality. If a greater quantity of code
also increases the overall quality, I can accept the former.
The original code is commented, but I removed them from the paste
because it is indeed a lot of code for someone to look over.

Looks like as if you should follow the acknowledged programming principle
to split a larger algorithm into smaller chunks (top-down, or bottom-up
programming). This also increases your chance of finding the expression
that causes the memory leak yourself.
[...]
As for ineffiency - are you referring to the repeated occurences of
'skinElement[skinElementID]' instead of replacing them with something
like 'var element = skinElement[skinElementID]', and then using
'element',

For example. Another sign are repeated property accesses to `length' in
`for' statements which can be equally avoided. And a property access to
`length' should not be necessary for XML objects in E4X by the `for each'
control statement. There is also the possibility of an alternative of
comparing boolean values to comparing string values with .toString() ==
"True" or .toString() == "False".
or is there a better approach than switch/case?

There is. You can map one value to another one with an Object object.
If E4X, and therefore an ECMAScript Edition 3 conforming implementation,
is a dependency, instead of

var result = "foo";

switch (x)
{
case "1":
result += "bar";

case "2":
result += "baz";

// ...

default:
result += "blubb";
}

result += "Bar";

you can and should write

var
result = ["foo"],
map = {
"1": "bar",
"2": "baz"
// ...
};

result.push(
(x in map) ? map[x] : "blubb",
"Bar");

result = result.join("");

almost always. (Note that this Object object inherits some properties from
Object.prototype, but their names are not numeric. If you want or need to
consider those too, for example because a substring can possibly equal the
name of such a property, you will have to use a control statement such as
`switch' instead of the `in' operator. The value of that property will be
pushed to the array instead otherwise. But at least you can avoid the
inefficient stepwise string concatenation of `+='.)


HTH

PointedEars
 
D

Doug Wright

I've tracked down the leak to a bug in Spidermonkey (Gecko's JS
engine). Nice to know (but annoying nonetheless) that the leak wasn't
due to anything I was doing.
 
T

Thomas 'PointedEars' Lahn

Doug said:
I've tracked down the leak to a bug in Spidermonkey (Gecko's JS
engine). Nice to know (but annoying nonetheless) that the leak wasn't
due to anything I was doing.

-v
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top