FB Profile says “it is a gc root”, but it seems wrong?

感情迁移 提交于 2019-12-22 17:38:56

问题


People like flash builder profile tool very much.But recently, a problem came to me when I tried to find a memory leak. Here is the simplified sample.

package
{
    import flash.display.Sprite;
    import flash.sampler.pauseSampling;
    import flash.system.System;

    import org.robotlegs.base.ContextBase;
    import org.robotlegs.mvcs.Context;

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

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

This is a simple class that create an object and then release it. When I use the profile perspective, it show me "live objects".

This is expected since I know that GC will free an object only when it doesn't have enough memory. Then I take a snapshot, to see the weird thing: Before I expand the path, it is like this:

And I am interested in the holder of context object, so I expand it:

That's so strange! As you see, nothing holds a reference to it.And it is implied to be a "GCRoot". I know articles about gc root, and it's quite simple(I read up to 20 articles about GC strategy to ensure my comprehension).It is no possible that the context is a gc root. And what's more, this isn't "1 path" at all! I hope it's a bug of profile tool, but I do want some explanations. So please forget about the "why not collect issue". I hope somebody tell me why the profile tool say"context is an gc root".Is it a bug or something? PS: I use flash builder 4.6 and flash debugger 11 sa.

来源:https://stackoverflow.com/questions/14000712/fb-profile-says-it-is-a-gc-root-but-it-seems-wrong

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!