Reputation: 427
I have this class that pulls out Library classes from a loaded .swf file. I noticed that everytime I remove the class from the stage somewhere in my App the class instance does not get Garbage Collected. Any suggestions?
package com.fullclip.utils {
import com.greensock.loading.LoaderMax;
import com.greensock.loading.SWFLoader;
import flash.display.DisplayObject;
public class LibraryAssets {
public static function getAsset(id:String, librarySRC:String):DisplayObject {
return getAssetFromLoader(id, LoaderMax.getLoader(librarySRC) as SWFLoader);
}
public static function getAssetFromLoader(id:String, library:SWFLoader):DisplayObject {
try {
var AssetClass:Class = library.getClass(id);
return new AssetClass() as DisplayObject;
}
catch (error:Error) {
Console.log("Could not find library asset: " + id);
Console.warn(error, error.getStackTrace());
}
return null;
}
}
}
Upvotes: 0
Views: 459
Reputation:
Not sure how your custom classes/libs handle unloading or what utilities they offer to unload, but I'm sure somewhere in the code they end up using the Loader object. In that case, you need to explicitly call unloadAndStop(true) which gives a hint to the GC letting it know it can now collect and dispose on that loaded swf. See the docs for more: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Loader.html#unloadAndStop()
Upvotes: 1