local NianGaoNode = requirePack("task.toyboxScripts.NianGaoNode")
local NianGaoNodePool = class("NianGaoNodePool")
function NianGaoNodePool:ctor()
self.nodePoll ={};
print(" 20 20 20 对象池的 构造 ")
end
function NianGaoNodePool:getNianGao()
if( #self.nodePoll > 0 ) then
local item = table.remove (self.nodePoll,1) --返回table数组部分位于pos位置的元素. 其后的元素会被前移. pos参数可选, 默认为table长度, 即从最后一个元素删起
print("10 獲取到舊的 前 " ,#self.nodePoll, item:getReferenceCount() )
--item:release();
-- print("10 獲取到舊的 後 " , item:getReferenceCount() )
return item ;
else
local item = NianGaoNode.new();
return item ;
end
end
function NianGaoNodePool:huishou(newNode)
print("22 remove 前 ", newNode:getReferenceCount())
newNode:removeFromParent();
print("22 remove 後 ", newNode:getReferenceCount())
newNode:retain();
print("22 retain 後 ", newNode:getReferenceCount())
if(newNode:getReferenceCount() > 2 ) then
newNode:release();
print("22 release 後 ", newNode:getReferenceCount())
end
table.insert(self.nodePoll,newNode) ; --table的数组部分指定位置(pos)插入值为value的一个元素. pos参数可选, 默认为数组部分末尾.
print("对象池的 回收之后",#self.nodePoll)
end
function NianGaoNodePool:clearAll()
-- this.enemyPool.clear(); // 通过 put 接口放入对象池
-- YBLog.log( "NodeBgPool","清理之后之后:",this.enemyPool.size() );
for k,v in ipairs(self.nodePoll) do
v:removeFromParent();
end
self.nodePoll = {}
end
return NianGaoNodePool