Memory doesn't release when removing MovieClips

I’m having a frustrating time understanding movie clips and memory usage of an AIR application I’m writing.

The app is basically an animated character that sits on screen and moves around doing stupid little animations. Each animation (Talking, Dancing, Jumping, etc) is an individual Movie Clip made up of around 50 or so PNGs in sequence. I’m using CS3 to create the clips, and exported them as SWCs for use in Flex.

When I addChild() the MovieClip to stage, memory usage increases, which makes sense. However when I use removeChild() on the same clip, and then add another clip, memory increases, and this goes on with every new clip… essentially leaving 10 clips in memory even if they aren’t being played.

Now, first thing you are going to think is I’ve got a reference to the clip somewhere and it’s not garbage collecting. Well, I’m using weak listeners everywhere, and I’m pretty sure I’ve killed every reference by NULLing out the objects.

I understand Garbage Collection doesn’t happen right away… but it never seems to happen. As a test, I wrote a really bare-bones app to attach and remove a clip to see if the memory ever frees. I’ve left the app running for a half hour after removing the clip from stage, and memory usage stays the same:


<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" frameRate="30" width="512" height="600" layout="absolute" applicationComplete="init()">
    <mx:Script>
        <![CDATA[
            private var testMC:MovieClip;
           
            private function init():void {
                addMC();
                addEventListener(Event.ENTER_FRAME, checkmem, false, 0, true);
            }

            private function addMC():void {
                testMC = new ClipIdle();
                this.rawChildren.addChild(testMC);
                System.gc();
                System.gc();
            }

            private function removeMC():void {
                this.rawChildren.removeChild(testMC);
                testMC = null;
                System.gc();
                System.gc();
            }
           
            private function checkmem(e:Event):void {
                trace( Number(System.totalMemory/1024).toFixed(0) + " KB");
            }
        ]]>
    </mx:Script>
    <mx:Button x="121.5" y="552" label="Add MovieClip" click="addMC()"/>
    <mx:Button x="292.5" y="552" label="Remove MovieClip" click="removeMC()"/>
</mx:WindowedApplication>

I’m also wondering if I could be having problems with the large number of PNGs I’m using. I’ve never done an app with so many frames of bitmap animation, and while the PNGs are only 15k compressed on disk, they obviously use more RAM (256x256 PNG with alpha channel, so (256*256)*4 = 250k each frame)

Any help is appreciated.

Thanks!