473,729 Members | 2,405 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Netscape 7.1 memory leaks

It seems that garbage collection is somewhat flawed in Netscape as the
following little script can bring a machine to its knees in about an
hour when run on Netstcape 7.1. I've tried freeing the variables
manually, but Im not sure whats broken. I assume that the images
aren't being freed when they are replaced. Is there a
workaround/solution to this? I've read some old postings about this in
4.x browsers, but I never saw a solution, and its apparently still not
been repaired.

Dennis

<html>
<head>
<script language="JavaS cript">
var myimage;

function randgen()
{
var date = new Date();

return date.getTime();
}
function loadIT()
{
myimage=new Image;

myimage.src="so meimage.jpg?ran d=" + randgen();
setTimeout("loa dIT()",1000);
}
loadIT();
</script>
</head>
<body>
</body>
</html>
Jul 23 '05 #1
18 1556
In article <3b************ *************@p osting.google.c om>,
de****@etinc.co m enlightened us with...
<script language="JavaS cript">
var myimage;

function randgen()
{
var date = new Date();
You keep making a new date. Why not reuse the same one?
Little scripts, this isn't an issue, but if it runs a lot, eventually
you'll run out of memory.

return date.getTime();
}
function loadIT()
{
myimage=new Image;


Same as above.

/old C programmer

--
--
~kaeli~
What if the Hokey Pokey IS what's it's all about?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #2
> setTimeout("loa dIT()",1000);

I beleive this is your problem. You have the loadIT() method call in
quotation marks so basically it is just a meaningless string. To actually
call the method the JavaScript engine will wrap the string in an annonymous
function everytime this line of code is called.

This new annonymous function is added to the window object. Hence the memory
consuption problem, because the life of the annonymous function is equal to
the life of the window object.

The Date object creation is not a problem becuase it's life span is much
shorter, basically just the life of the method call that creates it.

To fix this problem simply rewrite that line of code to be

setTimeout(load IT,1000);

Now instead of a meanlingless string, you are passing a function handle
which the method simple executes without adding any new objects into memory.

Hope this helps
Mike
Jul 23 '05 #3
Mike wrote:
setTimeout("loa dIT()",1000);
I beleive this is your problem. You have the loadIT() method call in
quotation marks so basically it is just a meaningless string. To
actually call the method the JavaScript engine will wrap the string
in an annonymous function everytime this line of code is called.


setTimeout has supported strings as its first argument longer than it
has supported function references as its first argument (and so in more
browsers). It is unlikely that setTimeout would create a function object
in order to execute the string, it would only be necessary to pass it on
to the - eval - function in order to have it executed.
This new annonymous function is added to the window object.
Even if an anonymous function object was created for the execution of a
string argument to setTimeout there is no reason to expect it to be
added to the window object (and if it was added what property name would
be used?).
Hence the
memory consuption problem, because the life of the annonymous
function is equal to the life of the window object.
The continuous creation of Image objects is more likely the source of
the memory leak (assuming that there is one, as no demonstration of the
phenomenon has been provided).
The Date object creation is not a problem becuase it's life span is
much shorter, basically just the life of the method call that creates
it.

To fix this problem simply rewrite that line of code to be

setTimeout(load IT,1000);

Now instead of a meanlingless string, ...

<snip>

That string was never meaningless, it is valid javascript source code,
as should be provided when a string argument is used with setTimout.

Richard.
Jul 23 '05 #4
Richard Cornford wrote:
Mike wrote:
setTimeout(" loadIT()",1000) ;
I beleive this is your problem. You have the loadIT() method call in
quotation marks so basically it is just a meaningless string. To
actually call the method the JavaScript engine will wrap the string
in an annonymous function everytime this line of code is called.

setTimeout has supported strings as its first argument longer than it
has supported function references as its first argument (and so in more
browsers). It is unlikely that setTimeout would create a function object
in order to execute the string, it would only be necessary to pass it on
to the - eval - function in order to have it executed.

This new annonymous function is added to the window object.

Even if an anonymous function object was created for the execution of a
string argument to setTimeout there is no reason to expect it to be
added to the window object (and if it was added what property name would
be used?).


This is correct. Spidermonkey (the JS engine in Netscape/Mozilla) will
create function objects as it would an integer or date. All objects are
JSObject types, regardless of being a function, a string, a date, or a
custom type. All objects are subject to garbage collection.
Hence the
memory consuption problem, because the life of the annonymous
function is equal to the life of the window object.

The continuous creation of Image objects is more likely the source of
the memory leak (assuming that there is one, as no demonstration of the
phenomenon has been provided).


It seems like the image objects would be garbage collected as well, but
there could be a cache thing going on. How big is the cache set to? (I
am not sure if this matters or not). Since each Image object is
associated with a cache entry (each image is randomly generated), it
could be rooting the image objects in the Spidermonkey engine.

OP: Does it exhibit this behavior when the cache is lower? How about
when it is turned off?

Can you point us to a link that causes this to happen? Does this happen
in any other browsers? (IE, Safari, Opera, etc)

Just some ideas,
Brian

Jul 23 '05 #5
Brian Genisio wrote:
<snip>
... . Spidermonkey (the JS engine in Netscape/Mozilla)
will create function objects as it would an integer or date.
All objects are JSObject types, regardless of being a function,
a string, a date, or a custom type. ...

<snip>

If code provided to setTimout as a string argument was executed in an
anonymous function then an - arguments - object would be available to
it. A quick test of:-

setTimeout('ale rt(typeof arguments);',10 0);

setTimeout(func tion(){alert(ty peof arguments);},10 0);

Suggests that the code provided as a string argument is not executed in
an anonymous function on Mozilla browsers.

Richard.
Jul 23 '05 #6
Richard Cornford wrote:
Brian Genisio wrote:
<snip>
... . Spidermonkey (the JS engine in Netscape/Mozilla)
will create function objects as it would an integer or date.
All objects are JSObject types, regardless of being a function,
a string, a date, or a custom type. ...


<snip>

If code provided to setTimout as a string argument was executed in an
anonymous function then an - arguments - object would be available to
it. A quick test of:-

setTimeout('ale rt(typeof arguments);',10 0);

setTimeout(func tion(){alert(ty peof arguments);},10 0);

Suggests that the code provided as a string argument is not executed in
an anonymous function on Mozilla browsers.

Richard.


Yeah, sorry, I was not completely clear in what I was saying. I was
saying "If a function object is being created..." in response to your
"Even if an anonymous function object was created for the execution..."
statement. I was making no assumptions about the way setTimeout (or
other similar functions) executes the code, only working off the
prefaced assumption that it does create an anonymous function object.

In reality, I was agreeing completely with what you were saying, by
backing it up with my understanding of the NS JS engine :)

Have a day!
Brian

Jul 23 '05 #7
"Richard Cornford" <Ri*****@litote s.demon.co.uk> wrote in message news:<c6******* ************@ne ws.demon.co.uk> ...
Brian Genisio wrote:
<script language="JavaS cript">
var myimage;

function randgen()
{
var date = new Date(); You keep making a new date. Why not reuse the same one?
Little scripts, this isn't an issue, but if it runs a lot, eventually
you'll run out of memory.
Well if I dont get a "new date" is ceases to do with the function is
intended to do. Its a local variable, so I would think that garbage
collection would have no problem disposing of local variables.
<snip>
... . Spidermonkey (the JS engine in Netscape/Mozilla)
will create function objects as it would an integer or date.
All objects are JSObject types, regardless of being a function,
a string, a date, or a custom type. ...

<snip>

If code provided to setTimout as a string argument was executed in an
anonymous function then an - arguments - object would be available to
it. A quick test of:-

setTimeout('ale rt(typeof arguments);',10 0);

setTimeout(func tion(){alert(ty peof arguments);},10 0);


Given all of this philosophical banter, I've tested it both ways and
it makes no difference in terms of lost memory. In fact I think I've
tested every variation of "normal" code possible, which is why I
originally concluded that the problem had to do with the ".src" object
not being freed when it is replaced. Assuming Im correct, any ideas on
how to explicitly free the image object before replacing it? "new"
should free the old one, I would think. I've also tried:

myImage = new Image;

function()
{
myImage.src=nul l;
myImage.src="wh atever";
}
with the same memory loss. Its quite baffling. I dont know if I
mentioned it, but ALL of these variations show NO memory loss in IE,
no matter how badly I code it (just so someone says something nice
about MS once in a while :-)

Dennis
Jul 23 '05 #8
Dennis wrote:
"Richard Cornford" <Ri*****@litote s.demon.co.uk> wrote in message news:<c6******* ************@ne ws.demon.co.uk> ...
Brian Genisio wrote:
<script language="JavaS cript">
var myimage;

function randgen()
{
var date = new Date();


You keep making a new date. Why not reuse the same one?
Little scripts, this isn't an issue, but if it runs a lot, eventually
you'll run out of memory.

Well if I dont get a "new date" is ceases to do with the function is
intended to do. Its a local variable, so I would think that garbage
collection would have no problem disposing of local variables.

<snip>
... . Spidermonkey (the JS engine in Netscape/Mozilla)
will create function objects as it would an integer or date.
All objects are JSObject types, regardless of being a function,
a string, a date, or a custom type. ...


<snip>

If code provided to setTimout as a string argument was executed in an
anonymous function then an - arguments - object would be available to
it. A quick test of:-

setTimeout('a lert(typeof arguments);',10 0);

setTimeout(fu nction(){alert( typeof arguments);},10 0);

Given all of this philosophical banter, I've tested it both ways and
it makes no difference in terms of lost memory. In fact I think I've
tested every variation of "normal" code possible, which is why I
originally concluded that the problem had to do with the ".src" object
not being freed when it is replaced. Assuming Im correct, any ideas on
how to explicitly free the image object before replacing it? "new"
should free the old one, I would think. I've also tried:

myImage = new Image;

function()
{
myImage.src=nul l;
myImage.src="wh atever";
}
with the same memory loss. Its quite baffling. I dont know if I
mentioned it, but ALL of these variations show NO memory loss in IE,
no matter how badly I code it (just so someone says something nice
about MS once in a while :-)

Dennis


What about the cache thing that I mentioned?

I dont know if I would call what you are experiencing a memory leak. A
memory leak is where memory continues to grow, and the program looses
track of it. I am guessing that Netscape has not lost track of the
memory, but is just holding on to it instead.

You might try asking this question in:
netscape.public .mozilla.dom
netscape.public .mozilla.jseng

Your question might be slightly off topic in both of those groups, but
the people there might have the knowledge to help.

Brian
Jul 23 '05 #9
Brian Genisio <Br**********@y ahoo.com> wrote in message news:<40******* *@10.10.0.241>. ..
Dennis wrote:
"Richard Cornford" <Ri*****@litote s.demon.co.uk> wrote in message news:<c6******* ************@ne ws.demon.co.uk> ...
Brian Genisio wrote:
<script language="JavaS cript">
var myimage;

function randgen()
{
var date = new Date();


You keep making a new date. Why not reuse the same one?
Little scripts, this isn't an issue, but if it runs a lot, eventually
you'll run out of memory.

Well if I dont get a "new date" is ceases to do with the function is
intended to do. Its a local variable, so I would think that garbage
collection would have no problem disposing of local variables.

<snip>

... . Spidermonkey (the JS engine in Netscape/Mozilla)
will create function objects as it would an integer or date.
All objects are JSObject types, regardless of being a function,
a string, a date, or a custom type. ...

<snip>

If code provided to setTimout as a string argument was executed in an
anonymous function then an - arguments - object would be available to
it. A quick test of:-

setTimeout('a lert(typeof arguments);',10 0);

setTimeout(fu nction(){alert( typeof arguments);},10 0);

Given all of this philosophical banter, I've tested it both ways and
it makes no difference in terms of lost memory. In fact I think I've
tested every variation of "normal" code possible, which is why I
originally concluded that the problem had to do with the ".src" object
not being freed when it is replaced. Assuming Im correct, any ideas on
how to explicitly free the image object before replacing it? "new"
should free the old one, I would think. I've also tried:

myImage = new Image;

function()
{
myImage.src=nul l;
myImage.src="wh atever";
}
with the same memory loss. Its quite baffling. I dont know if I
mentioned it, but ALL of these variations show NO memory loss in IE,
no matter how badly I code it (just so someone says something nice
about MS once in a while :-)

Dennis


What about the cache thing that I mentioned?

I dont know if I would call what you are experiencing a memory leak. A
memory leak is where memory continues to grow, and the program looses
track of it. I am guessing that Netscape has not lost track of the
memory, but is just holding on to it instead.

You might try asking this question in:
netscape.public .mozilla.dom
netscape.public .mozilla.jseng

Your question might be slightly off topic in both of those groups, but
the people there might have the knowledge to help.

Brian

Since it "holds onto it" until the browser is closed (and the OS has
to do it), I think it would qualify as a leak. There's too many bugs
in Mozilla to bother reporting such things, and you'll lose more
customers telling people to upgrade their buggy netscape browsers than
you will telling them to fire up IE in the long run anyway.
Jul 23 '05 #10

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

Similar topics

4
16689
by: Maurice | last post by:
Hi there, I'm experiencing big memory problems on my webserver. First on an old RedHat 7.2 system, now on an other fresh installed Suse 8.2 system: Linux version 2.4.20-4GB (root@Pentium.suse.de) (gcc version 3.3 20030226 (prerelease) (SuSE Linux)) #1 Wed Aug 6 18:26:21 UTC 2003 Apache 1.3.27-41 PHP 4.3.1-52 MySQL 3.23.55-20
0
1868
by: Steve Binney | last post by:
My code makes synchronous HttpWebRequest and HttpRebResponse calls. In VS 2003, I am getting memory leaks and event handle leaks. I am closing all streams and using "using"statements. I have used .Net memory profiler from Sci Tech to analyze the leaks and they are coming from inside HttpWebRequest and HttpRebResponse. When I run my code on VS2005, I do not get any leaks. Is this problem fixed in .Net 1.1 SP1? I may not be able to wait...
4
2350
by: Morten Aune Lyrstad | last post by:
Ok, now I'm officially confused. I have a large project going, which uses a win32 ui library I am developing myself. And I'm getting weird memory leaks. I don't know if I can explain what is going on, but I really need some help on this one. Ok, so I have this class defined (written by Randy Charles Morin, www.kbcafe.com) which detects memory leaks. It creates a memory check point in the constructor, and another in the destructor, and...
2
4957
by: Generic Usenet Account | last post by:
I have been using STL for a long time now, without any problems. Recently we generated a purification report on our software using Rational Purify, and we found some memory leaks. My colleague claims that some of the memory leaks are due to the fact that "STL is wrought with memory leaks". Of course I disagree. I think that there are no "inherent leaks" with STL, but if used improperly, leaks will occur. One common source of leak that...
8
3412
by: ranjeet.gupta | last post by:
Dear All Is the Root Cause of the Memory corruption is the Memory leak, ?? suppose If in the code there is Memory leak, Do this may lead to the Memory Corruption while executing the program ? In nut shell, what is/are the realtion/s between the Memory Leak and Memory Corruption. Juts Theoritical Assumtion below:
4
5723
by: ali.jan | last post by:
Hi, It is trivial to load an assembly in a new Application Domain. Is there any way of loading an assembly in a new process? I tried using the Process class like this: Process p = new Process() p.StartInfo.FileName = mStartupFile p.StartInfo.UseShellExecute = False
23
4558
by: James | last post by:
The following code will create memory leaks!!! using System; using System.Diagnostics; using System.Data; using System.Data.SqlClient; namespace MemoryLeak
3
5324
by: Jim Land | last post by:
Jack Slocum claims here http://www.jackslocum.com/yui/2006/10/02/3-easy-steps-to-avoid-javascript- memory-leaks/ that "almost every site you visit that uses JavaScript is leaking memory". Anybody know anything about this? Does *Javascript* leak memeory, or does the *browser* leak memory?
16
5096
by: graham.keellings | last post by:
hi, I'm looking for an open source memory pool. It's for use on an embedded system, if that makes any difference. Something with garbage collection/defragmentation would be nice. It should have the ability to allocate different size chunks of memory not just a single size. It should error check for double free, etc. And it should be usable by a mixture of C and C++ subsystems. If I get that, I'm happy. Thank you very much.
0
8921
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
9284
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
9202
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
9148
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
8151
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...
0
6022
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4796
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3238
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
2683
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.