无论我做什么
- 每次调用后都会StageWebView.dispose() - 重置舞台
问题仍然存在。每次加载网页都会增加3mb的内存,逐渐增加到超过1gb并崩溃应用程序。
我没有在StageWebView实例上设置任何事件侦听器。我绝对没有持有对它的引用。第二个URL加载后,内存就无法完全重置。
在AIR中运行以下代码可以看到此情况:
package kazo
{
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Rectangle;
import flash.media.StageWebView;
import mx.controls.Button;
import mx.core.UIComponent;
import flash.system.System;
/**
* ...
* @author KM
*/
public class Controller extends UIComponent
{
private var stageWeb:StageWebView;
private var url:uint = 0;
private const URL_ARRAY:Array = [
'http://www.mmo-champion.com/',
'http://www.bbc.co.uk/news/',
'http://www.twitch.tv/riotgames/',
'http://www.stackoverflow.com/'
]
/**
*
*/
public function Controller()
{
addEventListener(Event.ADDED_TO_STAGE, init);
}
/**
*
* @param e
*/
private function init(e:Event):void {
removeEventListener(Event.ADDED_TO_STAGE, init);
stageWeb = new StageWebView();
stageWeb.stage = stage;
stageWeb.viewPort = new Rectangle(0, 80, width, height - 50);
var btn:Button = new Button();
addChild(btn);
btn.label = 'Load URL';
btn.x = 0;
btn.y = 10;;
btn.width = 100;
btn.height = 30;
btn.addEventListener(MouseEvent.CLICK, load);
btn = new Button();
btn.label = 'Try to GC';
btn.x = 150;
btn.y = 10;;
btn.width = 100;
btn.height = 30;
addChild(btn);
btn.addEventListener(MouseEvent.CLICK, tryGC);
/// 26,576k
}
/**
*
* @param e
*/
private function load(e:MouseEvent):void {
if (!stageWeb) {
stageWeb = new StageWebView();
stageWeb.stage = stage;
stageWeb.viewPort = new Rectangle(0, 80, width, height - 50);
}
stageWeb.loadURL(URL_ARRAY[url % 4]);
url++;
}
/**
*
* @param e
*/
private function tryGC(e:MouseEvent):void {
stageWeb.stage = null;
stageWeb.viewPort = null;
stageWeb.dispose();
stageWeb = null;
System.gc();
}
}
}
有没有人对这个有经验?