In the ARPG page tour scene, the frequently killed monster object needs to be repeatedly generated, destroyed. Frequent triggering of garbage collection can reduce the efficiency of the game, and object pooling technology is to solve this problem
Object Pool Features:
1, the aggregation has a container, the container is equipped with the generated objects;
2, the encapsulation object generation operation;
3, the Packaging object destruction operations;
============================================================
============== Simple example of an object pool that can be automatically expanded ===========================
public class Objectpool
{
protected var pool:array = [];
protected Var Cl:class;
private var count:int = 0;
Public Function Objectpool (c:class)
{
this.cl = C;
}
/** Get instance */
Public Function GetObject ():* {
if (Pool.length > 0) {
return Pool.pop ();
}else{
Trace ("Current number of objects" + (++count));
return new Cl;
}
}
/** Recycle instance, there is no processing of OBJ's properties, it is recommended to process it yourself before recycling */
Public Function Recycle (obj:*): void{
Pool.push (obj);
}
/** Empty */
Public Function Release (): void{
Pool = [];
}
}
Object Pooling Technology