473,698 Members | 2,274 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 1082
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
5766
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
15704
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
8672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9156
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
9021
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...
1
8892
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
4361
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4614
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3038
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
2323
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1998
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.