PDA

View Full Version : garbage collection in MVC



tezzutezzu
February 16th, 2009, 10:35 AM
Hello there,

I have a question about garbage collection:
I am using a MVC pattern for a photo gallery website.
Every view displays a thumb viewer/controller and an image loader.
Each view extends an abstract class that has a close() method that looks like this




//AbstractViewer class

public function close():void {
while(this.numChildren) {
var d:DisplayObject = getChildAt(numChildren-1);
trace("removing")
removeChild(d);
d=null
}
dispatchEvent(new ViewEvent(ViewEvent.CLOSE));
}


This method is invoked when I change from one view to another. But according to my stats graph the RAM memory is not freed when the view is changed but new memory is allocated to open a new view.

This is the method I use for changing views:



//Main Class

private function sectionChanged():void {

var oldDisplay:AbstractView = currentDisplay;
logo.visible=false;

switch(String(data.currentSection.@type)) {

case "intro":
currentDisplay = new Intro(data, this.stage);
logo.visible=true;
logo.changeColour(0xFFFFFF)
break;

case "text":
currentDisplay = new Text(data, this.stage);
break;

case "blog":
currentDisplay = new Blog(data, this.stage);
break;

case "exhibition":
currentDisplay = new Exhibition(data, this.stage);
break;

case "contact":
currentDisplay = new Contact(data, this.stage);
break;

case "archive":
currentDisplay = new Archive(data, this.stage);
break;

}

oldDisplay.addEventListener(ViewEvent.CLOSE, initDisplay,false, 0,true);
oldDisplay.close();

bg.changeColour(int(data.currentSection.@colour.sp lit(",")[0]))
}



My memory is not constantly going up but only when I change view.

Any ideas?

Thanks!

.ral:cr
February 16th, 2009, 01:18 PM
GC runs from time to time, so if you set some vars to null the memory will not be freed imediately

tezzutezzu
February 17th, 2009, 04:24 AM
Hey ral, thanks for the reply. I have been waiting but memory seems to not to go down.
I guess that all boils down to a question: if I remove a DisplayObjectContainer, and set it to null, making sure to have all weak references in my listeners, will the children of this DisplayObjectContainer be removed as well?