Link to home
Start Free TrialLog in
Avatar of Donelson
Donelson

asked on

garbage collection: arrays

If I have a large array

  theArray:Array = new Array();

and I add 50,000 elements etc. then need to "flush" all those elements...

Should I use --

   theArray = [ ] ;

Will that do it?  OR should I use :

  theArray = new Array( );

to ensure that the previous contents are garbage-collected ?

Please explain for ---> BOTH  Flash 7  and  Flash 8 ...

Thanks


ASKER CERTIFIED SOLUTION
Avatar of trigger-happy
trigger-happy
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Donelson
Donelson

ASKER

Okay, thanks.

NOTE:

If I say --

  theArray[5] = createEmptyMovieClip("foo", 10);

then say

  delete theArray;

then the movieClip "foo" does not go away ever, but the array does. (looking at the _root objects)
The thing is that delete is meant to get rid of references, in order to get rid of the movieclip, you're going to have to do something like theArray[5].unloadMovie();
theArray[5].removeMovieClip();
delete theArray;

Chances are that if you're using theArray to contain references to MovieClips, then you're going to have to loop through the array and delete the movieclips manually and then finally delete the entire array.

--trigger-happy
Thanks, TH. Yes, that is what I'm doing, but I was curious as to the garbage-collection of "unreferenced objects" that Flash is supposed to do.  It must be that movieClips keep their reference on the _root (etc) so are not automatically gc'd.