I have a game that basically generates several (10 or more) display.newSprite() objects every 2-4 seconds… then it does that 10 or more times. (the sprites are spider sprites)
Each spider sprite starts at or below the bottom of the screen and move up towards the top. The player has to “touch” each spider as it moves up the screen, or the player misses it.
Each time a spider is added, I add it to a table I’ve created called spiders. I add it kinda like this:
[lua]local spider = spidersobject.newSpider(type)
spider:play()
spiders[i] = spider
localGroup:insert( spiders[i] )[/lua]
Now, if the spider is “missed” or “touched”, I try to kill the object kinda like this:
[lua] local function killspider(i, escaped)
print(’\n\n=============\nremoving spider '… i)
local spider_type = spiders[i].type
spiders[i].halt = true
spiders[i].escaped = escaped
spiders[i].type = spider_type
spiders[i].doremove = false
spiders[i].isremoved = true
spiders[i]:removeEventListener(“touch”, touchspider)
spiders[i]:removeSelf()
print(’--------Debug---------’)
for k,v in pairs(spiders[i]) do
print(k,v)
end
end[/lua]
HOWEVER, every few seconds I print out my memory usage and it goes up and up and up (over 1200 sometimes), and never comes down. ALSO, you’ll notice in my code above where I print Debug, that shows this, which to me seems like it doesn’t actually remove the event listener…
direction 1
score 34
halt true
isremoved true
doremove false
speedx 3
\_class table: 0x5639630
\_functionListeners table: 0x22c4270
hasevent true
speed 93
escaped true
type 5
\_proxy userdata: 0x2263614
alpha 1
Any help, guys? Am I removing sprites the wrong way? Is having all these sprites in a table screwing me up?
Thanks,
David [import]uid: 60144 topic_id: 24466 reply_id: 324466[/import]