display.newRect memory leak ?

Hi,
I’ve been investigating various memory leak issues with my code and decided to whittle it down
to a basic example (see below).

It would appear that display.newRect() leaks memory slightly. Is this the case, or am I missing something obvious in the code?

Thanks for any advice offered.

Regards,
Nuimo

local prevMemCount = 0  
local function monitorMem()  
 collectgarbage()  
 local memCount = collectgarbage("count")  
  
 if (prevMemCount ~= memCount) then  
 print( "MemUsage: " .. memCount)  
 prevMemCount = memCount  
 end  
  
end  
  
local k  
local rect;  
  
for k = 1, 10000 do  
 rect = display.newRect(math.random(0, 200), math.random(0,100), 200, 200);  
 rect:removeSelf();   
end  
  
print("end"); monitorMem();  
Runtime:addEventListener( "enterFrame", monitorMem )  
  

[import]uid: 87194 topic_id: 23646 reply_id: 323646[/import]

When I ran your example in the latest daily build, here’s the output I get:

MemUsage: 1362.7998046875MemUsage: 502.791015625MemUsage: 268.416015625[/code]Then nothing gets printed after the last item, even after an extended period of time waiting for it to change. That indicates that there is no memory leak.What build are you using? [import]uid: 52430 topic_id: 23646 reply_id: 94911[/import]

Thanks for the swift reply.
Apologies, I missed a line of code on line 12 !!
print(“start”); monitorMem();
I get the output below:

Interestingly, the memory usage at the start (around 77) is much lower than at the end (around 268). It seems that on every iteration of the loop, more memory is used. It may be a mistake in my code, but I can’t for the life of me spot it.

Thanks again.
Nuimo,

Copyright © 2009-2011 A n s c a , I n c .
Version: 2.0.0
Build: 2011.704
The file sandbox for this project is located at the following folder:
(/Users/Me/Library/Application Support/Corona Simulator/memory leak-632C1D0E09E42153497880FA357965D7)

start  
MemUsage: 77.6982421875  
end  
MemUsage: 1362.9560546875  
MemUsage: 502.88671875  
MemUsage: 268.51171875  

[import]uid: 87194 topic_id: 23646 reply_id: 94927[/import]