delete image in Firefox

Y

Yun

Hi folks,

I have a problem trying to delete some images that I previously load
in one array. My code looks like this :

// This is a global var
images = new Array();

function load_images() {

var time = new Date().getTime();

for (var i=0; i<=nimages, i++) {
delete images;
images = new Image();
images.src = image_path+i+".png?d="+time
}

At the end of the image name I set ".png?d=124151353546". This is
because I update the images every 5 minutes and the function is called
again. If I don't change the name of the image (using this trick ?
=....) the browser could think that the image is the same and it won't
change anything.

The problem I have using this code is that the image is not destroyed
by the browser (Firefox 4 in my case). After 3 or 4 hours, the web
site takes the whole RAM and I can't continue working.

Why delete images is not working ? or How could I do to destroy the
images I won't use again ?
Thank you for your help,

Yun
 
T

Tom de Neef

Yun said:
Hi folks,

I have a problem trying to delete some images that I previously load
in one array. My code looks like this :

// This is a global var
images = new Array();

function load_images() {

var time = new Date().getTime();

for (var i=0; i<=nimages, i++) {
delete images;
images = new Image();
images.src = image_path+i+".png?d="+time
}


What happens when you use
for (var i=0; i<nimages, i++) {
images.src = image_path+i+".png?d="+time
}

Tom
 
Y

Yun

Are you suggesting to not delete the object Image ? Mmmmhhh... I will
try it next Monday and I will let you know.

For some reason, the browser (Firefox) keeps the images in memory. I
think I will have the same problem if I don't delete the object.
Anyway, I don't see the logic of all of this.

Thank you Tom, I will post the result as soon as possible.
Yun
 
M

Martin Pearman

Hi folks,

I have a problem trying to delete some images that I previously load
in one array. My code looks like this :

// This is a global var
images = new Array();

function load_images() {

var time = new Date().getTime();

for (var i=0; i<=nimages, i++) {
     delete images;
     images = new Image();
     images.src = image_path+i+".png?d="+time

}

At the end of the image name I set ".png?d=124151353546". This is
because I update the images every 5 minutes and the function is called
again. If I don't change the name of the image (using this trick ?
=....) the browser could think that the image is the same and it won't
change anything.

The problem I have using this code is that the image is not destroyed
by the browser (Firefox 4 in my case). After 3 or 4 hours, the web
site takes the whole RAM and I can't continue working.

Why delete images is not working ? or How could I do to destroy the
images I won't use again ?
Thank you for your help,

Yun


Is the problem that the browser is caching stagnant images?

That's nothing to do with javascript and therefore there is nothing
that you can do about it.

In Firefox address bar enter "about:cache" and see details about
memory usage (refresh the page as your image refreshes) - does that
indicate that your images are being cached in memory by Firefox - and
that the images are not javascript memory leaks?

warwound
 
Y

Yun

Hello Martin,

Thank you for your help... I didn't know this option "about:cache", it
is very useful.
I realized that your are right, the stagnant images are cached in
memory by Firefox and I lost the reference to them. That shocks me !

So, even if I destroy the object Image, the image is still cached by
the browser and I can not do anything about it. That's new, I didn't
have this problem using Firefox 3.6...

Another thing :

image aux = new Image();
aux.src = 'image_1.png'
aux.src = 'image_2.png'

In this case, and if I understand correctly, "image_1.png" will be
also cached by the browser and I can not do anything to flush from the
cache. Is that right ?

Thank you for your help guys,
Yun
 
Y

Yun

Hello Martin,

Thank you for your help... I didn't know this option of checking the
cache, it is very useful.
I realized that your are right, the stagnant images are cached in
memory by Firefox and I lost the reference to them. That shocks me !

So, even if I destroy the object Image the image is still cached by
the browser and I can not do anything about it. This is new, I didn't
have this problem using Firefox 3.6...

Another thing.

image aux = new Image();
aux.src = 'image_1.png'
aux.src = 'image_2.png'

In this case and if I understand correctly, "image_1.png" will be also
cached by the browser and I can not do anything to flush from the
cache ?

Thank you for your help,
Yun
 
D

dhtml

Hi folks,

I have a problem trying to delete some images that I previously load
in one array. My code looks like this :

// This is a global var
images = new Array();

function load_images() {

var time = new Date().getTime();

for (var i=0; i<=nimages, i++) {
     delete images;
     images = new Image();
     images.src = image_path+i+".png?d="+time

}

At the end of the image name I set ".png?d=124151353546". This is
because I update the images every 5 minutes and the function is called
again. If I don't change the name of the image (using this trick ?
=....) the browser could think that the image is the same and it won't
change anything.

The problem I have using this code is that the image is not destroyed
by the browser (Firefox 4 in my case). After 3 or 4 hours, the web
site takes the whole RAM and I can't continue working.

Use Expires or Cache-Control HTTP headers.

http://www.mnot.net/cache_docs/

The delete operator doesn't remove objects from browser memory. You've
removed a reference to the image and if no other references exist, the
browser may reclaim that memory but it doesn't have to.

I've seen similar in Apple's "Advanced Best Practices":

http://developer.apple.com/library/...nceptual/JSCodingGuide/Advanced/Advanced.html

| Release initialization functions. Code that’s called once
| and never used again can be deleted after its execution.
| For instance, deleting a window’s onload handler function
| releases any memory associated with the function, like this:
|
|
| var foo = function()
| {
| // code that makes this function work
| delete foo;
| }
|
| window.addEventListener('load', foo, false);

Which, if they'd tested it, won't delete `foo` because variables have
an internal attribute that in ECMAScript 3 is called [[DontDelete]].
Attempts to `delete` a variable in ES5 in strict mode result in
SyntaxError.

What they could have done instead is to remove the event listener and
set `foo=null` (though in most cases that isn't going to make a hill
of beans).
Why delete images is not working ? or How could I do to destroy the
images I won't use again ?

Use Expires or Cache-Control on the images sent from the server.

http://www.mnot.net/cache_docs/
 
S

SAM

Le 17/07/11 05:00, Yun a écrit :
image aux = new Image();
aux.src = 'image_1.png'
aux.src = 'image_2.png'

In this case and if I understand correctly, "image_1.png" will be also
cached by the browser and I can not do anything to flush from the
cache ?

can you do something for all the images already seen elsewhere and also
cached ?
 
R

Ry Nohryb

X-No-Archive: Yes

(...)

The problem I have using this code is that the image is not destroyed
by the browser (Firefox 4 in my case). After 3 or 4 hours, the web
site takes the whole RAM and I can't continue working.
(...)

I've seen that same problem before, in some version of iOS IIRC.
Perhaps if you do a location.reload() every now and then, it may work.
At least it did on the iphone (iirc). A setInterval(reload,
halfAnHour) or something...
 
D

dhtml

Use Expires or Cache-Control HTTP headers.
I'm interested to know if you have tried this and what the results
were. I've not experienced the problem you are having and so never
tried this solution. Theoretically, I think it should work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top