# Creating a new instance with the same variable reference

**URL:** <https://forum.kirupa.com/t/creating-a-new-instance-with-the-same-variable-reference/319914>\
**Category:** flash\
**Created:** [March 8, 2011, 2:46pm UTC](https://forum.kirupa.com/t/creating-a-new-instance-with-the-same-variable-reference/319914 "2011-03-08T14:46:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcelozep](https://avatars.discourse-cdn.com/v4/letter/m/8edcca/32.png) [@marcelozep](https://forum.kirupa.com/u/marcelozep)\
**Post date:** [March 8, 2011, 2:46pm UTC](https://forum.kirupa.com/t/creating-a-new-instance-with-the-same-variable-reference/319914/1 "2011-03-08T14:46:42Z")

</div>

There´s any need to set to null a reference in this case?

private function initGame():void{  
game= new Game()  
}  
private function endGame():void{  
removeChild(game)  
//here, should I set game to null?  
}

then, to start a new game:

initGame()

In this case, do I need to set game to null at endGame? Or by adding a new game instance to game variable, the previous instance has no more reference and so is eligible for garbage collection?

Thanks ![](http://forum.kirupa.com/uploads/kirupa/5541/fb5b90eb3225b77d.gif)
