1. Using weak references is the last thing you should do, whenever possible
you should avoid it. By doing so you leave all means of control of the
object, and if the object has some kind of behavior that will keep it
"alive", you won't be able to delete it ever (example, the *deleted* object
did not close LocalConnection).
It is not possible to conclude from what you describe whether objects will
be removed or not. The objects will be removed when there will be no
reference to the "roots". "Roots" are local variables, or field
initializers. These are either persistent or temporary, local variables
would be an example of temporary "roots".
Imagine this life span of an object:

public var persistent:Object;
public var anotherProperty:Object;
public var revealPresense:Dictionary = new Dictionary(true);

public function DocumentClass()
{
    super();
    var temporary:Object = new Object(); // the object created, put into the
heap, bound to the temporary toot
    persistent = temporary; // the object is in heap, now referenced by two
variables.
} // temporary variable is destroyed, now the object is only referenced by
persistent root.

public function anotherMethod():void
{
    anotherProperty = persistent; // the object is still in heap, but now
has two persistent roots.
    persistent = null; // the object is still not eligible for GC, it is
referenced by persistent root.
    revealPresense[anotherProperty] = true; // let's store a weak reference
and observe the object deletion.
    anotherProperty = null; // the object is no longer referenced, but may
exist for some time.
    for (var obj:Object in revealPresense) trace( obj ); // it may be still
here...
    setInterval(checkPresense, 1);
}

public function checkPresense():void
{
    for (var obj:Object in revealPresense) trace( obj ); // it may be still
here...
}

Reply via email to