Like the title says, I'm trying to come up with the most efficient way to remove a sprite that contains other sprites and bitmaps.
Say for example I've this following sprite. What should be the best way to remove it?
local group = Sprite.new()
local g1 = Sprite.new()
local g2 = Sprite.new()
group:addChild(g1)
group:addChild(g2)
local g3 = Sprite.new()
g2:addChild(g3)
local b1 = Bitmap.new(...)
g1:addChild(b1)
local b2 = Bitmap.new(...)
g2:addChild(b2)
local b3 = Bitmap.new(...)
g3:addChild(b3) |
I'm trying to finetune this following function to remove the parent sprite-
local function clearSprite(group)
local n = group:getNumChildren()
print("N "..n)
if n == 0 then
if group.pool then
group.pool:free(group) ---I'm pooling bitmaps. So if group is a bitmap, it gets freed and returned to its pool
group.pool = nil
end
print("removeFromParent()")
group:removeFromParent()
group = nil
else
for i = n, 1, -1 do
local child = group:getChildAt(i)
clearSprite(child)
end
group:removeFromParent()
group = nil
end
end |
I'm not sure it's working perfectly because I'm seeing a rise in the lua memory every time I use clearsprite(group).
So how do you guys remove sprites? Any and all ideas to tackle this thing are deeply appreciated. Thanks.
Comments
Likes: Apollo14, MoKaLux, plicatibu
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
I've noticed that sometimes Lua doesn't auto-collect garbage at all (even after a long period of time). But after manual command 'collectgarbage()' everything is collected perfectly.
Also you should 'removeAllListeners()' (if there were any)
Likes: oleg, plicatibu
"What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
“The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
Likes: antix, plicatibu
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!
Thank you so much for taking the time to answer my question.
Likes: MoKaLux
Likes: plicatibu
To prevent this, try this:
https://play.google.com/store/apps/developer?id=razorback456
мій блог по гідерос https://simartinfo.blogspot.com
Слава Україні!