强制SWF从FLA时间轴上的代码释放已分配的内存

时间:2014-08-26 08:21:33

标签: actionscript-3 flash memory-leaks

我有一个Flash项目,我在时间轴上写了一些代码。当我加载SWF文件并卸载它时,分配的内存仍然存在,每次加载和卸载时都会发生内存泄漏。

有解决方案吗?

我试过这个,但内存不是免费的。

addEventListener(Event.REMOVED_FROM_STAGE, removed);

public function removed(evt:Event) {
    removeEventListener(Event.REMOVED_FROM_STAGE, removed);
    csc = null;
    if (currentFrame == 2) {
        content.removelisteners3()
        try {
            content.removeChildren();
        } catch (e:Error) {
        }
        menu.removeListeners1();

        try {
            mc1.mc.removeChildren();
        } catch (e:Error) {
        }
        try {
            mc1.removeChildren();
        } catch (e:Error) {
        }
    }

    if (currentFrame == 3) {
        menu.removeListeners2()
        try {
            search_ctn.removeChildren()
        } catch (e:Error) {
        }
        try {
            min_search.removeEventListener(MouseEvent.MOUSE_UP, f_min_search);
        } catch (e:Error) {
        }
        try {
            clos_search.removeEventListener(MouseEvent.MOUSE_UP, f_clos_search);
        } catch (e:Error) {
        }
        try {
            btnUpSearch.removeEventListener(MouseEvent.MOUSE_DOWN, f_btnUpSearch);
        } catch (e:Error) {
        }

    }
    try {
        this.removeChildren();
    } catch (e:Error) {
    }
}

1 个答案:

答案 0 :(得分:0)

删除内容并不能保证内存实际上被垃圾收集器释放。只要一个内存位置有引用它,它就会一直存在......并且......