|
-
flip-flopper
am i effectively removing this asset?
Can someone answer me this:
If I have a method of a class that extends MovieClip, that defines a variable like this within the method body:
var image:MovieClip = new MovieClip();
and then also adds image to the display list of the class instance in the same method:
addChildAt(image, 0);
and then outside of said method I load a bunch of bitmaps as children of the child at 0, and then remove it like this in a different method:
removeChildAt(0);
are all of those bitmaps also now gone and set aside for trash collection along with the movieclip itself, since the scope of the image variable was just the function that created the movieclip?
I don't have to destroy the movieclip or its children in any other way, do I?
Many thanks.
-
Provided nothing else has references to those resources, they are eligible for garbage collection. Be sure they don't have event handlers, or are included in arrays or other collections.
You should be fine.
-
flip-flopper
-
flip-flopper
follow up question, if you'd be so kind...
If I have created an instance of a class and that class contains a function that creates a Timer instance assigned to a variable in scope of that function, and also adds an event listener or two to that Timer instance:
If I nullify the variable to which that class instance was assigned, and thus remove the instance, do I need to first call a destroy() method of that class to remove the Event Listeners of that Timer in that function, or will they be trashed along with the instance? If so are Event Listeners the only thing you need to look out for, besides other variable references to the instance you created? What if the Timer instance was a class property instead of a function variable?
Maybe you know of a resource online that covers all of this trash cleanup business?
Many, many thanks.
-
Honestly, I do not know the answer to your question. Practically, I would go with the destroy approach, because even if the Timers are eligible for garbage collection, that is no guarantee of WHEN they will be collected, so the listeners will continue to run for some time.
-
flip-flopper
Sounds like a good answer to me. Thanks!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|