destroy (A.K.A. gabage collect) a movieclip/textfield

First of all, in order to free memory, any reference to the instance
needs to be deleted.

Secondly, removeMovieClip() will remove a MovieClip instance from Stage and removeTextField() will remove a TextField instance from Stage.

var tn:MovieClip = this.createEmptyMovieClip(“tn”, 0);
var tn_nested:MovieClip = tn.createEmptyMovieClip(“tnNested”, 0);
var tf_nested:TextField = tn.createTextField(“tf”, 1, 0, 100, 100, 100);
tf_nested.text = “hello world!”;

destroy_btn.onRelease = function(){


trace(“is tn instanceof MovieClip after removeMovieClip: “+(tn
instanceof MovieClip));//false
trace(“is tn instanceof Object after removeMovieClip: “+(tn
instanceof Object));//false
trace(“tn type after removeMovieClip: “+ typeof(tn));//movieclip
trace(“is tf_nested instanceof Object after removeMovieClip:
“+(tf_nested instanceof Object));//false
trace(“tf_nested type after removeMovieClip: “+(typeof(tf_nested)));/

trace(“tn is “+tn+”; tf_nested is “+tf_nested);//tn is ; tf_nested is

delete tf_nested;
delete tn;

trace(newline+”>>>>delete tn>>>>”);
trace(“tn after destroy: “+(tn instanceof MovieClip));
trace(“tn after destroy: “+(tn instanceof Object));
trace(“tn type after destroy: “+ typeof(tn));
trace(“tf_nested type after destroy: “+(typeof(tf_nested)));


The code above first calls removeMovieClip()/removeTextField() first to remove the instances in question and trace down and delete all their references to completely destruct them for garbage collection.


BTW,  instanceof MovieClip will return false after “removeMovieClip” is invoked on an mc while typeof(mc) will still return “movieclip”.


One Response to “destroy (A.K.A. gabage collect) a movieclip/textfield”

  1. kevin Says:

    Thanks, could not figure out how to delete dynamically created TextField instances without this.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: