3

I appreciate Robotlegs very much, but recently a GC problem came to me. I failed to dispose context object by just set the reference null.With the help of FB profile tool, I find that context object appears to be a "GC Root". To figure it out, I wirte a simple class, which creates a context obj and leave it unreachable.Here is the detail of this class:

public class MemoryLeak extends Sprite{
    public function MemoryLeak()
    {
        makeAndDrop();
    }

    public function makeAndDrop():void{
        var _context = new Context(this);
        _context = null;
    }
}

When I ran this class, I hoped it be disposed by GC, but it didn't work(most times, not everytime). And the profile tool show me this instance is a GCRoot. I read some articles about GC, but few of them mention GCRoot itself. Could anybody tell me why and thank you so much!

PS: I tried to call System.gc() twice after makeAndDrop() but it didn't work. In fact, I'm more interested in the "is GCRoot" issue(implied by the fb profile), it may help more if you tell me about it.

Creynders
  • 4,573
  • 20
  • 21
  • GC doesnt always run (eg if theres plenty of spare memory) and RL uses weak listeners which may affect GC too? –  Dec 20 '12 at 19:12
  • Is this context loaded as a module? Because I can't see another reason why it would be marked as GCRoot. Anyway, the reason why it's sometimes released and sometimes not, has to do with the automatic garbage collection, if the app has "enough" free memory left, objects can linger in memory for a looong time. – Creynders Dec 21 '12 at 17:09
  • http://stackoverflow.com/questions/14000712/why-is-it-a-bug-of-flash-builder-or-something – ForbetterCoder Dec 22 '12 at 08:45

1 Answers1

0

I think the Context will probably listen to this so that it can perform dependency injection on any added children or create mediators for them. One would hope that the listener would not be attached until you talk to the mediatorMap or the viewMap, but I think it is likely that the RL authors would not consider a use case where you'd want a Context on a View for a time period shorter than the View's actual lifespan.

Amy Blankenship
  • 6,485
  • 2
  • 22
  • 45