同一节点下,大量创建,删除节点,draw call 异常

项目测试中发现,在一个节点反复添加删除节点,数量大了之后,draw call 会变得异常多;
使用对象池得时候,问题会明显一点,不使用对象池,也会出现问题;
测试demo已经上传,通过不断反复得创建大量节点,再删除节点的重复操作,drawcall 会变得很大


TestNodePool.zip (21.3 KB)

以下是核心代码

numList = []
p:Vec3 = new Vec3();
//添加创建数组
onBtnAdd(){
let str = this.labelCount.string
let count = parseInt(str);
for(let i = 0; i < count; i++){
this.numList.push(1);
}
}
update(t){
this.nodeCount.string = this.nodeList.length.toString();
this.poolCount.string = this.nodePool.length.toString();

//分帧创建节点
let m = 3;
while(m > 0){
if(this.numList.length > 0){
let node = this.getNodefromPool();
if(node == null)
node = instantiate(this.cloneNode);
this.p.x = math.randomRangeInt(-400,400)
this.p.y = math.randomRangeInt(-300,300)
node.setPosition(this.p)
node.active = true;
this.rootNode.addChild(node);
let expNode = node.getComponent(nodeExp);
expNode.Init();
this.nodeList.push(expNode);
this.numList.pop();
}
m–;
}
}
lateUpdate(t){
//节点鼠标点击附近,回收节点
let dis = 0;
for(let i = this.nodeList.length-1 ; i >= 0; i–){
dis = Vec3.distance(this.touchPos, this.nodeList[i].node.position);
if(dis < 100)
{
this.recoverNode(this.nodeList[i].node);
this.nodeList.splice(i, 1);
}
}
}

//对象池
getNodefromPool(){
    if(this.nodePool.length > 0)
        return this.nodePool.pop();
    return null;
}
recoverNode(node:Node){
    node.active =false;
    node.removeFromParent();
    this.nodePool.push(node);
}

2D 渲染组件合批说明 · Cocos Creator

谢谢解答。
还是有些疑问,在删除节点后,这个buffer的数据不会清除吗?重复的做删除,增加操作会一直增加吗?这个buffer又接口可以手动重置吗

会删除的吧,不用对象池的情况下能正常删除,存入对象池的不会从buffer里删除的