473,563 Members | 2,856 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1076
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.prototyp e, 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
5727
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 macros */ #ifndef PUBLIC #define PUBLIC
13
1365
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 TRACKMOUSEEVENTs. This happens if I disable/enable a menuitem, add a new menuitem programatically or click on an entry in the mdiList menu. I am disposing the...
1
1446
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
1744
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 am doing is creating an instance of the class and then using its two methods (Connect CloseConnection) and then setting the instance to Nothing.
6
2294
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 an instance of class). With the container of STL, this may often result in a vector of smart pointers, or a smart pointer of STL container. Am I...
3
1551
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 internal error has occurred in the compiler). Below, a piece of code that produces the same error : ***** CLR - Class Library project *****
7
15677
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 lot of memory but I still had to use it. 1. After using DLLImport and seeing the memory leak I tried to load and
23
1953
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
1509
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 .. does python-3.0 improve something to avoid writing memory leaking applications? rupert.
0
7888
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8106
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6255
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.