Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > delete image in Firefox

Reply
Thread Tools

delete image in Firefox

 
 
Yun
Guest
Posts: n/a
 
      07-15-2011
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[i];
images[i] = new Image();
images[i].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[i] is not working ? or How could I do to destroy the
images I won't use again ?
Thank you for your help,

Yun
 
Reply With Quote
 
 
 
 
Tom de Neef
Guest
Posts: n/a
 
      07-16-2011
"Yun" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> 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[i];
> images[i] = new Image();
> images[i].src = image_path+i+".png?d="+time
> }
>


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

Tom


 
Reply With Quote
 
 
 
 
Yun
Guest
Posts: n/a
 
      07-16-2011
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
 
Reply With Quote
 
Martin Pearman
Guest
Posts: n/a
 
      07-16-2011
On Jul 15, 9:15*pm, Yun <(E-Mail Removed)> wrote:
> 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[i];
> * * *images[i] = new Image();
> * * *images[i].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[i] 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


 
Reply With Quote
 
Yun
Guest
Posts: n/a
 
      07-17-2011
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
 
Reply With Quote
 
Yun
Guest
Posts: n/a
 
      07-17-2011
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
 
Reply With Quote
 
dhtml
Guest
Posts: n/a
 
      07-18-2011
On Jul 15, 1:15*pm, Yun <(E-Mail Removed)> wrote:
> 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[i];
> * * *images[i] = new Image();
> * * *images[i].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/s.../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[i] 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/
--
Garrett
 
Reply With Quote
 
SAM
Guest
Posts: n/a
 
      07-18-2011
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 ?


--
Stéphane Moriaux avec/with iMac-intel
 
Reply With Quote
 
Ry Nohryb
Guest
Posts: n/a
 
      07-18-2011
X-No-Archive: Yes

On Jul 15, 10:15*pm, Yun <(E-Mail Removed)> wrote:
> (...)
>
> 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...
--
Jorge.
 
Reply With Quote
 
dhtml
Guest
Posts: n/a
 
      07-22-2011
On Jul 18, 8:29*am, dhtml <(E-Mail Removed)> wrote:
> On Jul 15, 1:15*pm, Yun <(E-Mail Removed)> wrote:

[...]
> > 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.

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.
--
Garrett
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
after an image is moved to a new location, how to delete the image at the old location? zxo102 Python 0 08-01-2006 04:58 PM
To delete or not to delete? Lethal Computer Support 15 07-24-2005 11:47 PM
Can someone tell me why I can't delete this file? and why it blue screens WinXP Pro on delete? zZz Computer Support 1 01-12-2005 02:37 AM
Cannot Delete, (The Delete Key Won't Work) Lee Something Computer Support 13 10-15-2003 09:51 PM
delete on delete ! Sandeep Grover C++ 19 07-22-2003 10:09 AM



Advertisments