Skip to main content
rjoshicool
Inspiring
March 4, 2010
Question

Remove instance of loaded SWF from memory

  • March 4, 2010
  • 1 reply
  • 702 views

I am loading an SWF file into another parent SWF. I remove the loaded SWF using the unloadAndStop() method and set the loader to null. But the instance of the loaded SWF still remains there in the memory. How can I fix this?

This topic has been closed for replies.

1 reply

March 4, 2010

After you've removed the loaded swf from the parent swf, and nulled the loader, the loaded swf will be marked for collection by the garbage collector on its next sweep. The IDE environment has a tendency to clean memory up less than in a browser. In any case, it will be removed from memory the next time Flash Player thinks it needs to free up some memory.

You *can* force the garbage collector to sweep through if it's absolutely needed, but I tend to find it causes a bit of slowdown. In the IDE environment you will need to do a little hack with LocalConnections.

import flash.net.LocalConnection;

import flash.system.System;


private function ForceGC():void

{

     // This is only necessary when testing in the IDE

     try

     {

          new LocalConnection().connect("foo");

          new LocalConnection().connect("foo");

     }


     // This bit alone will do the trick in a browser

     System.gc();

     System.gc();

}

Try that, if that doesn't clear the memory out, then there's probably another reference somewhere that needs nulling, such as an event listener.

Hope this helps

J

rjoshicool
Inspiring
March 5, 2010

I tried profiling the SWF using the Flex profiler. It shows me reference of the document class of the loaded module. But I am not able to trace the cause of why it isn't getting removed from the memory.