4 Replies Latest reply on Dec 24, 2008 12:53 PM by rtalton

    removeChildAt(0) not freeing up any memory

    Russell.Brown
      I'm building an image viewer that flips through images. Each image is contained in a component [Canvas] that stylizes the photo border. When I removeChildAt(0) the memory is never reclaimed. Each photo I throw on the page increases the memory with no decrease.

      As far as I can tell there are no references to these children. They are not interacted with after creation accept to be destroyed. Is there another method for destroying these? Removing a top level component would automatically remove all their children right? There should be no need to specifically delete the image as well correct?

      Even just some help with debugging the reason via profiler would go a long ways.

      Thanks
      Russ
        • 1. Re: removeChildAt(0) not freeing up any memory
          rtalton Level 4
          Here's some articles which may help explain what's happening in your app:
          http://livedocs.adobe.com/flex/3/html/help.html?content=profiler_6.html
          http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&productId=2&postI d=12030
          http://blogs.adobe.com/aharui/2007/03/garbage_collection_and_memory.html

          Essentially, calling removeChild() does not neccessarily remove it from memory; it depends on several other factors.
          • 2. Re: removeChildAt(0) not freeing up any memory
            Level 7

            "Russell.Brown" <webforumsuser@macromedia.com> wrote in message
            news:gitrrt$lec$1@forums.macromedia.com...
            > I'm building an image viewer that flips through images. Each image is
            > contained
            > in a component [Canvas] that stylizes the photo border. When I
            > removeChildAt(0)
            > the memory is never reclaimed. Each photo I throw on the page increases
            > the
            > memory with no decrease.
            >
            > As far as I can tell there are no references to these children. They are
            > not
            > interacted with after creation accept to be destroyed. Is there another
            > method
            > for destroying these? Removing a top level component would automatically
            > remove
            > all their children right? There should be no need to specifically delete
            > the
            > image as well correct?
            >
            > Even just some help with debugging the reason via profiler would go a long
            > ways.

            Why not just use one component, and change the Image's source property?


            • 3. Re: removeChildAt(0) not freeing up any memory
              Russell.Brown Level 1
              Because there are multiple images on the screen at once that are shuffled through. I could however create essentially a pool of objects and reuse them.

              While there are multiple workarounds that I can see, for my own growth's sake I want to better understand why something wouldn't be collected at garbage time.

              My current debacle is this. If I add a child and then remove it right away, everything works great. If I surround the removeChildAt(0) with an if statement making sure there are more than say 5 images, garbage collection fails to take back the memory from the removed children.

              This makes absolutely now sense to me what so ever.

              rtalton, thanks for the links, I'm trying my best to use them. While my understanding is better, I still can't figuere out why it doesn't work...
              • 4. Re: removeChildAt(0) not freeing up any memory
                rtalton Level 4
                Hopefully something in those links will catch your eye.
                Since there are many reasons why calling removeChild() doesn't always remove an object from memory, it's difficult to pinpoint without seeing all the code.
                One thing that I noticed is if you have any kind of reference to the child, it will live on after you remove it. Maybe your code is still referring to it through a variable.

                Also, this quote is from the help docs:
                "The RemoveChild class removes a child display object, such as a component, from a container as part of a view state. The child is only removed from the display list, it is not deleted."

                Do the components being removed have any event listeners? Remove them as you remove the components.