A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: am i effectively removing this asset?

  1. #1
    flip-flopper scottPadgett's Avatar
    Join Date
    Jan 2005
    Location
    Boston
    Posts
    425

    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.
    :: scott ::

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    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.

  3. #3
    flip-flopper scottPadgett's Avatar
    Join Date
    Jan 2005
    Location
    Boston
    Posts
    425
    Thanks for checking me.
    :: scott ::

  4. #4
    flip-flopper scottPadgett's Avatar
    Join Date
    Jan 2005
    Location
    Boston
    Posts
    425
    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.
    :: scott ::

  5. #5
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    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.

  6. #6
    flip-flopper scottPadgett's Avatar
    Join Date
    Jan 2005
    Location
    Boston
    Posts
    425
    Sounds like a good answer to me. Thanks!
    :: scott ::

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center