[OpenLayers-Users] [OpenLayers-Dev] Memory Leak in OpenLayers + IE

jesslacy jesslacy at us.ibm.com
Wed Nov 19 18:58:45 EST 2008


I ran across this (or what may be a similar) issue today in IE 6 using OL 2.7
for a layer with the alpha hack.

In the Image.js file, the initImgDiv method calls two observers:

      if (this.layerAlphaHack) { 
            OpenLayers.Event.observe(this.imgDiv.childNodes[0], 'load', 
                                     OpenLayers.Function.bind(onload,
this));    
        } else { 
            OpenLayers.Event.observe(this.imgDiv, 'load', 
                                 OpenLayers.Function.bind(onload, this)); 
        } 
...
         OpenLayers.Event.observe(this.imgDiv, "error",
                                 
But only one observer gets cleaned up in the destroy method.  

Changing:
           if (this.layerAlphaHack) {
               
OpenLayers.Event.stopObservingElement(this.imgDiv.childNodes[0].id);                
            } else {
                OpenLayers.Event.stopObservingElement(this.imgDiv.id);
            }
to
             if (this.layerAlphaHack) {
               
OpenLayers.Event.stopObservingElement(this.imgDiv.childNodes[0].id);                
                OpenLayers.Event.stopObservingElement(this.imgDiv.id);
            } else {
                OpenLayers.Event.stopObservingElement(this.imgDiv.id);
            }
has resolved the problem for me.

Regards,
Jess Lacy


bradleyspencer wrote:
> 
> List,
> 
> I'm not sure if I have this problem or how to verify it but I am having a
> lot of browser freeze ups with my testing.
> 
> I am getting this with 2.5 loaded on my server and whatever is the most
> recent online version.
> 
> Is there any update on this?
> 
> Cheers,
> 
> Brad Spencer
> 
> 
> -----Original Message-----
> From: Christopher Schmidt [mailto:crschmidt at metacarta.com]
> Sent: Wednesday, 28 March 2007 1:49 AM
> To: dev at openlayers.org
> Subject: [OpenLayers-Dev] Memory Leak in OpenLayers + IE
> 
> So, after some investigation this morning, I've discovered a source of a
> memory leak in Internet Explorer + OpenLayers:
> 
> 
> Currently, when creating Tile.Image images, we bind a load/error
> listener:
> 
>  OpenLayers.Event.observe(image, "load",
>                OpenLayers.Util.onImageLoad.bindAsEventListener(image));
>  OpenLayers.Event.observe(image, "error",
>               
> OpenLayers.Util.onImageLoadError.bindAsEventListener(image));
> 
> (Util.js, line ~180)
> 
> This is how we prevent tiles from displaying in the wrong location.
> Unfortunately, this closure on the image is never cleaned up, so IE
> doesn't destroy the images, even when the page is navigated away from,
> resulting in a memory leak.
> 
> No fix yet, just documenting this so that if anyone has an obvious 'oh,
> just do $foo', they can feel free to offer it up :)
> 
> Regards,
> --
> Christopher Schmidt
> MetaCarta
> _______________________________________________
> Dev mailing list
> Dev at openlayers.org
> http://openlayers.org/mailman/listinfo/dev
> 
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
> 
> 

-- 
View this message in context: http://www.nabble.com/-OpenLayers-Dev--Memory-Leak-in-OpenLayers-%2B-IE-tp13786396p20592288.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.




More information about the Users mailing list