Skip to main content
August 6, 2007
Question

Removing clips from the timeline in as 3.0

  • August 6, 2007
  • 2 replies
  • 280 views
Try this test:

Creat a new Flash movie with 2 bank keyframes.

Draw a rectangle on the first frame, convert it to a movieclip and give it an instance name of testSym

Add this code to the first frame:

////////////////////////////


removeChild(testSym);

testSym = null;

/////////////////////////


and then this code to the second frame:

//////////////////////


trace ("FORCING GC");
try {
new LocalConnection().connect('foo');
new LocalConnection().connect('foo');
} catch (e:*) {}
stop();

// this forces the garbage collector but is not recommended for published products
///////////////////////

give the rectangle movie clip 2 blank keyframes too. Put this code in the first frame:

///////////////////

trace("I'm still here");

/////////////////////

and this code in the second:

///////////////////

gotoAndPlay(1);

///////////////////

Now run the movie - I assumed that the clip would be marked for garbage collection and collected by the forced collect, but it still persists - presumably because it was put statically on the timeline?

Is there any way around this? Surely there must be a way to remove movie clips that have been placed statically on the timeline at design time rather than adding everything using code? Can anyone help?
This topic has been closed for replies.

2 replies

kglad
Community Expert
Community Expert
August 7, 2007
yes. from my testing i've found flash first sweeps for gc when the player occupies about 7500 kb of memory.
kglad
Community Expert
Community Expert
August 7, 2007
it's marked for gc but your two lcs aren't forcing gc so you're not seeing testSym get gc'd.

to force gc i use:

August 7, 2007
The thing is, if I removed testSym from the stage at design time and add it using addChild, it does get deleted.

Sorry, I don't quite understand your code, is it adding movieclips to push Flash to the memory threshold to run GC?