MultiPuck example - memory leak?

Hello again,

I was playing around with the multipuck example and noticed that is has a function to cull the pucks when they slide off screen as such:

-- Automatic culling of offscreen objects  
local function removeOffscreenItems()  
 for i = 1, #allDisks do  
 local oneDisk = allDisks[i]  
 if (oneDisk.x) then  
 if oneDisk.x \< -5 or oneDisk.x \> display.contentWidth + 5 or oneDisk.y \< -5 or oneDisk.y \> display.contentHeight + 5 then  
 oneDisk:removeSelf()  
 end   
 end  
 end  
end  
  

However when I inserted the memory leak monitoring code from Corona’s “SDK Memory Leak Prevention 101” tutorial I noticed that memory usage was continually going up, regardless of the fact that the pucks were being culled. Memory usage monitoring code:

local monitorMem = function()  
  
 collectgarbage()  
 print( "MemUsage: " .. collectgarbage("count") )  
  
 local textMem = system.getInfo( "textureMemoryUsed" ) / 1000000  
 print( "TexMem: " .. textMem )  
end  
  

I guess my question is, is the puck culling code designed to prevent a memory leaking? If not, what would need to be added to it so that it prevents the constant creep upwards in memory usage?

Thanks again! [import]uid: 78150 topic_id: 14917 reply_id: 314917[/import]

I think the array allDisks is growing all the time. Disk objects will be removed but the array elements stay.

Got it? [import]uid: 70114 topic_id: 14917 reply_id: 55090[/import]