delete image in Firefox

Discussion in 'Javascript' started by Yun, Jul 15, 2011.

  1. Yun

    Yun Guest

    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
    Yun, Jul 15, 2011
    #1
    1. Advertising

  2. Yun

    Tom de Neef Guest

    "Yun" <> schreef in bericht
    news:...
    > 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
    Tom de Neef, Jul 16, 2011
    #2
    1. Advertising

  3. Yun

    Yun Guest

    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
    Yun, Jul 16, 2011
    #3
  4. On Jul 15, 9:15 pm, Yun <> 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;
    >      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
    Martin Pearman, Jul 16, 2011
    #4
  5. Yun

    Yun Guest

    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
    Yun, Jul 17, 2011
    #5
  6. Yun

    Yun Guest

    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
    Yun, Jul 17, 2011
    #6
  7. Yun

    dhtml Guest

    On Jul 15, 1:15 pm, Yun <> 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;
    >      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/
    --
    Garrett
    dhtml, Jul 18, 2011
    #7
  8. Yun

    SAM Guest

    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
    SAM, Jul 18, 2011
    #8
  9. Yun

    Ry Nohryb Guest

    X-No-Archive: Yes

    On Jul 15, 10:15 pm, Yun <> 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.
    Ry Nohryb, Jul 18, 2011
    #9
  10. Yun

    dhtml Guest

    On Jul 18, 8:29 am, dhtml <> wrote:
    > On Jul 15, 1:15 pm, Yun <> 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
    dhtml, Jul 22, 2011
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sandeep Grover

    delete on delete !

    Sandeep Grover, Jul 12, 2003, in forum: C++
    Replies:
    19
    Views:
    609
    Chris \( Val \)
    Jul 22, 2003
  2. HeroOfSpielburg
    Replies:
    1
    Views:
    377
    Alf P. Steinbach
    Aug 6, 2003
  3. 0to60
    Replies:
    4
    Views:
    307
    Jerry Coffin
    Dec 19, 2003
  4. Mathieu Malaterre

    delete NULL, what about delete[] NULL

    Mathieu Malaterre, Aug 17, 2004, in forum: C++
    Replies:
    2
    Views:
    3,809
    Mathieu Malaterre
    Aug 17, 2004
  5. zxo102
    Replies:
    0
    Views:
    404
    zxo102
    Aug 1, 2006
Loading...

Share This Page