Egret destruction (memory leaks)

 

An array reference

When the scene is removed, the array reference value is automatically destroyed

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

	public constructor() {
		super();

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

  

When removing the scene, object reference array is automatically destroyed, Ball object is automatically destroyed 

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);
		}
	}
}

 

Two object references

When the scene is removed, the referenced object is automatically destroyed Ball

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

	public constructor() {
		super();

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

  

 Three UI components

When removing scenes, UI components are automatically destroyed

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";
	}
}

  

Four List

When removing the scene, List will be automatically destroyed

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]);
	}
}

  

 Five monitor

When removing the scene, listeners will be automatically removed out, HomeScene, List there listening, still will be destroyed

Listener the impression that there will not be recovered, but the test run, constantly repeated addition and removal of 100 scenes, memory has not increased.

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(){

	}
}

  

Guess you like

Origin www.cnblogs.com/gamedaybyday/p/12536362.html