Skip to main content
alexb25522528
Participant
May 13, 2016
Question

Movie clip garbage collection As3

  • May 13, 2016
  • 1 reply
  • 287 views

Hi guys,

I'm new to AS3 and I'm working on this game that involves several movie clips playing one right after the other and everything works great so far but I'm not sure it was wise of me to make the movie clips using image sequences and now I have this issue of RAM usage. Is there a way to clear the RAM using the garbage collection when the clip has finished playing and is no longer needed? As it is the game plays and the RAM just keeps adding up until it gets to around 12gb and crashes so clearly not ideal. Any ideas?

Thanks in advance

Alex

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
May 13, 2016

to allow animate pro to gc a movieclips you need to remove it from the display, remove all its listeners and null all its references.  eg, for

var mc:MovieClip=new MovieClip();

addChild(mc);

mc.addEventListener(MouseEvent.CLICK,f);

// you need to execute the following to enable mc to be gc'd:

removeChild(mc);

mc.removeEventListener(MouseEvent.CLICK,f);

mc=null;

alexb25522528
Participant
May 15, 2016

Oh thank you!!! I think I get it. So is making it a child necessary? Currently I don't have any of my movie clips set as children. I just initialised then from an array. So can I not set the mc=null if it isn't a child?

kglad
Community Expert
Community Expert
May 15, 2016

you don't have to add movieclips as children, but if they are never children, they're never shown.

further, if you create movieclips on the stage in the ide, those movieclips are children and must be removed from the display and all references to them must be nulled before they are eligible for gc.