Select to view content in your preferred language

Memory Leak on ArcGISDynamicMapServiceLayer?!

840
3
07-13-2010 12:04 PM
tommywang
New Contributor
I'm developing an application through the Sample Flex Viewer, and found a weird memory leak. I made a simple test application to test it out, and re-generate the problem. It's like every time I update the dynamicMapServiceLayer, 4MB memory will be added into the browser.

I need to update the layer visibility and layer definition on the fly through the code, and every time this function is called, I got the image back and everything looks good except the memory the leak.

Check the code below, hope someone can help me figure out.
               map1.visible=true;
       //create the Dynamic Map service object
      var myDLayer:ArcGISDynamicMapServiceLayer = map1.layers[0] as ArcGISDynamicMapServiceLayer;
                        
                       //Change the layers visibility, I have 3 layers in this service
       var myVisLayers:ArrayCollection = new ArrayCollection();
       myVisLayers.addItem("0");
       myVisLayers.addItem("1");
       myVisLayers.addItem("2");

   //initial layer definition array
   var myLayerDefinitions:Array = new Array();
   myLayerDefinitions.push("");
   myLayerDefinitions.push("");
   myLayerDefinitions.push("");
   
   myDLayer.visibleLayers= myVisLayers;
   myVisLayers=null;
   myDLayer.layerDefinitions = myLayerDefinitions;
   myLayerDefinitions=null;
   myDLayer.alpha = 1;
   myDLayer.visible=true;
                        myDLayer.Refresh()

Tags (2)
0 Kudos
3 Replies
ReneRubalcava
Frequent Contributor II
I can reproduce this, but in my case the memory is freed up after a few seconds. Turning a Dynamic Map Service visbility from false to true does add about 4MB of load to the memory. But like I said, when I monitor my app, it clears up after a few seconds.

I imagine it has to do with Flash reloading the cached tiles from browser memory, but that's just a guess. Flash Garbage collection can be a bit tricky, you can never really determine when it will happen, you can't force it in a production environment. Best you can do is make sure you remove listeners and unused objects and cross your fingers. 😛
0 Kudos
tommywang
New Contributor
thank you odoe!

I did remove a lot of stuff, but it still increase even in this simple code. However, I will keep monitor the memory and see if it will reduce after map loaded. At least mine is not free in couple of seconds.
0 Kudos
DasaPaddock
Esri Regular Contributor
Here's a good blog post on this subject:
http://blogagic.com/163/flex-memory-management-and-memory-leaks
0 Kudos