memory leak with polygons?
I'm running into a memory issue while displaying polygons. I'm loading the polygons into a secondary map that is removed when the viewer closes the slide. The map and slide appear to be removed but the memory from the loaded polygons does not decrease and eventually the app fails. Do I need to loop through each polygon and manually remove it each time the user closes the slide or is there another solution?
Thanks
Thanks
1
person has this question
I have this question, too!
Tell me when someone answers.
The more people who ask this question, the more it gets noticed.
The more people who ask this question, the more it gets noticed.
Create a customer community for your own organization
Plans starting at $19/month
-
Inappropriate?From your description I'm really not sure. The PolygonMarkers do keep a reference to the map so maybe that's screwing things up?
Can you set up a minimal demo somewhere so we can debug it together? -
Inappropriate?I uploaded 2 versions of the app. (without the positioning elements). The first is located at http://marwp.cla.umn.edu/amap/MapOnly... and displays a secondary map when you click on one of the points in the main map. This version seems to release the map from memory when the slide or secondary map closes. The second version is located at http://marwp.cla.umn.edu/amap/MapWith... and displays polygons in the secondary map when you click on a point in the main map. This version does not release the polygons from memory when the slide closes.(there are several points that do not contain polygons in case you click on a point that does not display a series of house polygons) I've tried a variety of thing to get the polygons to unload from the secondary map without success. I'm removing all listeners including those attached to each house (marker), using removeAllMarkers to remove the houses, removing all children associated with the polygons in the secondary map but nothing seems to work to unload these elements. I'll paste in the code that I'm using to load these polygons below. Thanks.
private function placePolygons(_dbArray:Array):void {
var o:Object;
var p:Object;
var extLocations:Array = new Array;
//add children for polygon marker
polygonClip=new PolygonClip(smallMap);
polygonClip.addEventListener(MarkerEvent.MARKER_ROLL_OVER, onMarkerRollOver,false,0,true);
polygonClip.addEventListener(MarkerEvent.MARKER_ROLL_OUT, onMarkerRollOut,false,0,true);
smallMap.grid.addChild(polygonClip);
//loop through the dataset and place the polygons
for each (o in _dbArray) {
var locations:Array = new Array;
var geomString:String=o.astext;
var pattern1:RegExp= /MULTIPOLYGON\(\(\(/g;
var pattern2:RegExp=/\)\)\)/g;
if (o.astext != null) {
geomString=geomString.replace(pattern1,"");
geomString=geomString.replace(pattern2,"");
var coords:Array=geomString.split(",");
for each (p in coords) {
var str:String = p.toString();
var parts:Array = str.split(/\s* \s*/, 2);
parts=parts.reverse();
locations.push(new Location(parseFloat(parts[0]),parseFloat(parts[1])));
extLocations.push(new Location(parseFloat(parts[0]),parseFloat(parts[1])));
}
polygon=new PolygonMarker(smallMap,locations,false);
polygon.fillAlpha=.7;
polygon.mouseEnabled=true;
if (o.textstring != null) {
polygon.title = "building number: " + o.textstring;
} else {
polygon.title = "building not catalogued";
}
polygonClip.attachMarker(polygon,polygon.location);
}
}
smallMap.setExtent(MapExtent.fromLocations(extLocations));
//----- changed by TB --
//---- fadein and visible moved from openslide to fix
//---- refresh issue
//fadeIn();
visible=true;
//--------------------------------
} -
Inappropriate?Thanks for expanding on the issue (and sharing your work in progress, it looks great!).
If you're removing markers with removeMarkerObject that does sound like an issue with the PolygonClip and PolygonMarker code. What do you do with your reference to polygonClip after the above code has run? Do you explicitly remove it from the stage (smallMap.grid.removeChild(polygonClip)?). And the same question but for the smallMap - have you tried setting all these things to null?
I'm not sure what else to try here, but I will see if I can reproduce the issue soon.
Oh, just one more question from me... How are you monitoring memory usage? Obviously I can see the difference between the two versions you posted, but i have no idea which one uses more memory :) -
Inappropriate?Thanks. I'm using trace(((System.totalMemory)/1024)/1024+" mb"); and am also monitoring the memory with the task manager. I'm also running the following "removeAllChildren" to remove polygonClip and some of the others. I have a similar function that removes the listeners as well. The following function has polygonClip.removeAllMarkers(); commented but I've tried it with this and without but didn't see any different in the memory. Thanks again for your help.
private function removeAllChildren():void {
if(polygonClip){
while (polygonClip.numChildren > 0){
trace("number of polygonClip children="+ polygonClip.numChildren);
polygonClip.removeEventListener(MarkerEvent.MARKER_ROLL_OVER, onMarkerRollOver);
polygonClip.removeEventListener(MarkerEvent.MARKER_ROLL_OUT, onMarkerRollOut);
polygonClip.removeChildAt(polygonClip.numChildren-1);
// When the last child is removed, stage is set to null, so quit
if (polygonClip == null )
break;
}}
//polygonClip.removeAllMarkers();
if(smallMap.grid){
while (smallMap.grid.numChildren > 0) {
trace("number of smallmap.grid children="+ smallMap.grid.numChildren);
smallMap.grid.removeChildAt(smallMap.grid.numChildren-1);
// When the last child is removed, stage is set to null, so quit
if (smallMap.grid == null )
break;
}}
if(smallMap){
while (smallMap.numChildren > 0) {
trace("number of smallmap children="+ smallMap.numChildren);
smallMap.removeChildAt(smallMap.numChildren-1);
// When the last child is removed, stage is set to null, so quit
if (smallMap == null )
break;
}}
if(this){
while (this.numChildren > 0) {
trace("number of children="+ this.numChildren);
this.removeChildAt(this.numChildren-1);
// When the last child is removed, stage is set to null, so quit
if (this == null )
break;
}}
} -
Inappropriate?I found it!!! The problem was in my amfphp class and not with the polygons. I'm using amfphp to pull in my coordinates for the polygons. There were a few listeners that I was using in that class that apparently were preventing flash from releasing the polygons or their coordinates from memory. This made it look like the problem was in the polygonMarker but it was hidden elsewhere. When I removed these listeners the memory was unloaded (or at least most of it was). Thanks.
1 person says
this answers the question
-
Inappropriate?Great, thanks for letting us know!
Loading Profile...



EMPLOYEE