473,387 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Code is leaking and I can't figure out why

Hi

The code in question is available from

http://mozilla.pastebin.com/596645

Any help would be extremly appreciated, because I've spent many hours
on trying to figure this out!!

Mar 11 '06 #1
5 1067
Doug Wright wrote:
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
Mar 12 '06 #2
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?

Mar 12 '06 #3
Doug Wright wrote:
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
Mar 12 '06 #4
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.

Mar 17 '06 #5
Doug Wright wrote:
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
Mar 17 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
by: Robin Cole | last post by:
I'd like a code review if anyone has the time. The code implements a basic skip list library for generic use. I use the following header for debug macros: /* public.h - Public declarations and...
13
by: Rich B. | last post by:
I have an MDI form with a single child form. I have found a couple of circumstances that appear to cause the framework to leak Int32s, MenuItems, MenuItemCollections and sometimes...
1
by: Sameer | last post by:
Hi friends, I am new to c++. I have a code in C, void *malloc(); code_value=malloc(100*sizeof(unsigned int)); // some code free(code_value);
7
by: Brano | last post by:
Hi all, I have a VB.NET Dll that is invoked via BizTalk 2002 AIC over Http protocol. the Dll is making a connection using a 3rd party connector to a Unidata database (old legacy stuff) All I...
6
by: zl2k | last post by:
hi, When I considered about preventing memory leaking, the method came up to my mind is using boost smart pointer if possible (use stl::vector instead of type, use smart pointer whenever declare...
3
by: hyd | last post by:
Hello, I use VS2005 - C++/CLI. I have some kind of events in native C++. I want to raise .NET events when my native C++ events occur. So, I wrote some code for that but I have an C1001 error (An...
7
by: Ragnar Agustsson | last post by:
Hi all I have been wandering about the best way to sandbox memory leaks in 3rd party libraries when using them from the .Net framework. I have a 3rd party library, written in C++, that leaks a...
23
by: gNash | last post by:
#include <stdio.h> #include <string.h> #include <stdlib.h> char * strclear(const char *str) { char *string; string=(char *)malloc(strlen(str)+1); strcpy(string,str); return string;
3
by: rupert.thurner | last post by:
the edgewall trac release 0.11 is blocked now since more than one month for a memory leak nobody is able to find, see http://groups.google.com/group/trac-dev/browse_thread/thread/116e519da54f16b...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.