473,700 Members | 3,126 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 1083
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
5767
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
1374
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 main menu in the child form as well as in the main mdi form, so that's not the issue. I have seen...
1
1454
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
1751
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
2301
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 making things too complicated or this is an usual implementation? Thanks in advance. zl2k
3
1558
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
15706
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
1976
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
1515
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
8638
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9202
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9058
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8909
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7791
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6555
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3081
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
2
2371
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2018
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.