Hi,
we are developing a rather large application that dynamically displays some maps with varying layer configurations.
In the code I have variables like:
var mapCanvas:Group;
var map:Map;
In some function I instantiate the map and add it to the group like:
map = new Map();
mapCanvas.addElement(map);
then add layers to the map. Everything works quite fine.
Now (in some other function) I do the following:
map.removeAllLayers();
map.layers = null;
map.lods = null;
mapCanvas.removeElement(map);
map = null;
The problem I have is that the instance of the Map class is not collected by the garbage collector. Also a lot of LOD, SpatialReference and Extent classes stay in memory. It seems that some internal references in the Map class are not cleared up and no functionality to do this manually is exposed. This causes a considerable memory leak after a while.
Example: After instantiating the map, say, 10 times with different layer configurations, I have something like 10 Map instances in memory, also 914 LOD instances, 226 SpatialReference instances and 135 Extent instances.
Those are never collected by the garbage collector.
Also, I cannot reuse the instance of the Map class because after calling the removeAllLayers() function, setting a new layer on the map with a different spatial reference does not work.
Am I missing somethig here? Any thoughts on this are very much appreciated.
Chris