MozillaZine

Memory leak with images?

Discuss how to use and promote Web standards with the Mozilla Gecko engine.
Markusv
Guest
 

Post Posted March 6th, 2007, 7:08 am

Hi
on my webpage I am refreshing images with javascript, and firefox is using more and more memory, especially on a Mac. Both my winxp and my mac run the most recent firefox version (2.0.0.2). This makes my page use a lot of memory.

Any help would be greatly appreciated!

Markus

malliz
Folder@Home

User avatar
 
Posts: 43842
Joined: December 7th, 2002, 4:34 am
Location: Australia

Post Posted March 6th, 2007, 7:10 am

Sounds like your Javascript code is a bit dodgy
What sort of man would put a known criminal in charge of a major branch of government? Apart from, say, the average voter.
"Terry Pratchett"

schapel
 
Posts: 3483
Joined: November 4th, 2002, 10:47 pm
Location: Ann Arbor, Michigan

Post Posted March 6th, 2007, 8:16 pm

Markusv wrote:on my webpage...

What's the URL of the webpage? If you give it to us, we can check out if it's a problem with Firefox or not.

Dartman
Moderator

User avatar
 
Posts: 11997
Joined: February 9th, 2006, 9:43 pm

Post Posted March 6th, 2007, 8:30 pm

Markusv

This needs to be discussed in the Web Development Forum. However, you have to be registered to be moved to that forum.

Register, reply back here and I will move you.
Alcohol and Calculus don't mix. Never drink and derive.

markusv
 
Posts: 5
Joined: March 7th, 2007, 1:18 am

Post Posted March 7th, 2007, 1:20 am

hi
I have no registered with the user name markusv, when you transfer me can you give me a link to the new post?

The only thing my javascript does is setting a new src for the image. I can not see how this should be a error in my javascript code..

Markus

schapel
 
Posts: 3483
Joined: November 4th, 2002, 10:47 pm
Location: Ann Arbor, Michigan

Post Posted March 7th, 2007, 5:35 am

markusv wrote:The only thing my javascript does is setting a new src for the image...

It might be <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=228233">bug 228233</a>.

Dartman
Moderator

User avatar
 
Posts: 11997
Joined: February 9th, 2006, 9:43 pm

Post Posted March 7th, 2007, 7:59 am

markusv wrote:hi
I have no registered with the user name markusv, when you transfer me can you give me a link to the new post?


Hi markusv,

There will be no new link, nor will you need to repost this question in the other forum. I will move this thread/topic over to the Web Development Forum for you.

Moving to Web Development.
Alcohol and Calculus don't mix. Never drink and derive.

markusv
 
Posts: 5
Joined: March 7th, 2007, 1:18 am

Post Posted March 8th, 2007, 2:06 am

looks like it might be bug 228233 yes. It has not been resolved yet!? Is there any way to avoid the bug?

schapel
 
Posts: 3483
Joined: November 4th, 2002, 10:47 pm
Location: Ann Arbor, Michigan

Post Posted March 8th, 2007, 5:16 am

The bug was reported over three years ago and has only two votes. It doesn't seem like users think it's a big deal, so I'm not surprised it hasn't been fixed. They're looking for someone to work on fixing it.

As for a workaround, I can't see that anyone has come up with one. Perhaps you could discuss it in the bug report.

jscher2000

User avatar
 
Posts: 10743
Joined: December 19th, 2004, 12:26 am
Location: Silicon Valley, CA USA

Post Posted March 8th, 2007, 3:37 pm

To avoid the problem of changing out the image before it has finished loading, use the image's onload event handler. Here's a simple example:
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Image Intervals</title>
<script type="text/javascript">
function timerCallback() {
    var NUM_OF_SLIDES = 18;
    var randomnumber = Math.floor(Math.random()*NUM_OF_SLIDES)
    var nuImgName = "test"+randomnumber+".jpg";
    var slideImg = document.getElementById("slideImage");
    slideImg.onload = timerDelay;
    slideImg.src = nuImgName;
      // For logging debug info only
      var debug = document.getElementById("filenames");
      debug.innerHTML += "<br>\n" + nuImgName;
}
function timerDelay() {
  setTimeout("timerCallback()", 500);
}
window.onload = function() {
    timerDelay();
  };
</script>
</head>
<body>
<div id="container">
    <img id="slideImage" src="">
<div>
<!-- for Logging debug info only -->
  <p id="filenames">Debug Info:</p>
</body>
</html>

Note to anyone testing this: you need 18 or 19 images named starting with test0.jpg to avoid the script stopping.

markusv
 
Posts: 5
Joined: March 7th, 2007, 1:18 am

Post Posted March 9th, 2007, 1:20 am

Thank you for your suggestion but there already is a delay of about five seconds before the image.src is changed. The src i swap with might be different from the image already in use or it might be the same..

jscher2000

User avatar
 
Posts: 10743
Joined: December 19th, 2004, 12:26 am
Location: Silicon Valley, CA USA

Post Posted March 9th, 2007, 4:10 pm

markusv wrote:Thank you for your suggestion but there already is a delay of about five seconds before the image.src is changed. The src i swap with might be different from the image already in use or it might be the same..

But does it solve the memory leak, and can you solve it your way? ;-)

broesel75
 
Posts: 2
Joined: June 3rd, 2007, 10:19 pm

Post Posted June 3rd, 2007, 11:06 pm

Hello,
this is exact the problem i am struggling with. The page runs some seconds and than the memory usage of firefox 2.0.0.4 explodes, goes up to 300MB and than my system crashes (I use always the same image url and read the image from a webcam, I reduced the delay to speed up the problem). Is there a solution for this problem?

Regards
Broesel

Racer
 
Posts: 6108
Joined: November 18th, 2002, 11:07 am

Post Posted June 4th, 2007, 10:25 am

I'm surprised this has not been addressed yet. There are quite a few sites that do dynamic image loading using this method. Since the bug hasn't been looked at since 2005, I don't forsee any forthcoming fix unless alot of noise is made -- squeaky wheel & such.

schapel
 
Posts: 3483
Joined: November 4th, 2002, 10:47 pm
Location: Ann Arbor, Michigan

Post Posted June 4th, 2007, 12:07 pm

Racer wrote:I'm surprised this has not been addressed yet. There are quite a few sites that do dynamic image loading using this method. Since the bug hasn't been looked at since 2005, I don't forsee any forthcoming fix unless alot of noise is made -- squeaky wheel & such.

If you can name some sites that cause Firefox to exhibit this memory problem, please do. That will help convince developers that the issue needs to be addressed.

Return to Web Development / Standards Evangelism


Who is online

Users browsing this forum: No registered users and 4 guests