# Garbage collection in MVC

**URL:** <https://forum.kirupa.com/t/garbage-collection-in-mvc/281998>\
**Category:** Uncategorized\
**Created:** [February 16, 2009, 3:35pm UTC](https://forum.kirupa.com/t/garbage-collection-in-mvc/281998 "2009-02-16T15:35:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tezzutezzu](https://avatars.discourse-cdn.com/v4/letter/t/df705f/32.png) [@tezzutezzu](https://forum.kirupa.com/u/tezzutezzu)\
**Post date:** [February 16, 2009, 3:35pm UTC](https://forum.kirupa.com/t/garbage-collection-in-mvc/281998/1 "2009-02-16T15:35:20Z")

</div>

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

```php

//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:

```php

//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.split(",")[0]))
	}

```

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

Any ideas?

Thanks!
