Issue: When using states in mxml, components that have been added with the <mx:AddChild> tag, can not be cleanly removed and therefore they stuck in memory
Tested version: Flex Milestone 3.2
Workaround: Unfortunately there is none. Either you do not use States any more or you compile your own Flex-SDK and fix the classes DeferredInstanceFromFunction and DeferredInstanceFromClass, which holds instances of your added component, even when the corresponding state is not active any more. Another possibility would be to create your own AddChild class that does not use the DeferredInstance classes, see Nick Bilyk’s blog post: Flex states retaining memory
Note: These is the (shortened) source code of DeferredInstanceFromClass (nearly same source in DeferredInstanceFromFunction), where I’ve highlighted the retained reference to the instance that has been created. I have no idea why they store the instance in a private variable, must be some performance intentions.
package mx.core
{
public class DeferredInstanceFromClass implements IDeferredInstance
{
[..]
private var instance:Object = null;
/**
* Creates and returns an instance of the class specified in the
* DeferredInstanceFromClass constructor, if it does not yet exist;
* otherwise, returns the already-created class instance.
*
* @return An instance of the class specified in the
* DeferredInstanceFromClass constructor.
*/
public function getInstance():Object
{
if (!instance)
instance = new generator();
//this should be: return new generator();
return instance;
}
}
}
firstrow RIA e.U.