Egret销毁问题(内存泄漏)

筅森魡賤 提交于 2020-03-21 05:56:45

 

一 数组引用

移除场景时,值引用数组自动销毁

class HomeScene extends eui.Component{
	public arr:Array<Number> = [];	

	public constructor() {
		super();

		for(let i=0;i<10000;i++){
			this.arr.push(i);
		}
	}
}

  

移除场景时,对象引用数组自动销毁,Ball对象自动销毁 

class HomeScene extends eui.Component{
	public arr:Array<Ball> = [];	

	public constructor() {
		super();

		for(let i=0;i<10;i++){
			let ball:Ball = new Ball();
			this.arr.push(ball);
			this.addChild(ball);
		}
	}
}

 

二 对象引用

移除场景时,引用对象Ball自动销毁

class HomeScene extends eui.Component{
	public ball:Ball;	

	public constructor() {
		super();

		this.ball = new Ball();
		this.addChild(this.ball);
	}
}

  

 三 UI组件

移除场景时,UI组件自动销毁

class HomeScene extends eui.Component{
	public btn0:eui.Button;
	public btn1:eui.Button;
	public btn2:eui.Button;
	public btn3:eui.Button;
	public btn4:eui.Button;
	public btn5:eui.Button;
	public btn6:eui.Button;
	public btn7:eui.Button;
	public btn8:eui.Button;

	public constructor() {
		super();
		this.skinName = "HomeSceneSkin";
	}
}

  

四  List

移除场景时,List会自动销毁

class HomeScene extends eui.Component{
	public list:eui.List;

	public constructor() {
		super();
		this.skinName = "HomeSceneSkin";

		this.list.itemRenderer = ListItem;
		this.list.dataProvider = new eui.ArrayCollection([1,2,3,4,5]);
	}
}

  

 五  监听

移除场景时,监听会自动移除掉,HomeScene、List有监听,仍然会被销毁

印象中有监听不会被回收,但是测试来看,不停的反复增加和移除100个场景,内存并没有增加。

class HomeScene extends eui.Component{
	public list:eui.List;

	public constructor() {
		super();
		this.skinName = "HomeSceneSkin";

		this.list.itemRenderer = ListItem;
		this.list.dataProvider = new eui.ArrayCollection([1,2,3,4,5]);

		this.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTouchTap, this);
		this.addEventListener(egret.Event.REMOVED_FROM_STAGE, this.onRemove, this);
		this.list.addEventListener(egret.Event.CHANGE, this.onChange, this);
	}

	private onTouchTap(){
		
	}

	private onRemove(){
		 
	}

	private onChange(){

	}
}

  

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