Hi,
Thanks for the great SDK and sharing good stuffs from the developers.
I’m new to corona sdk and I’m confusing about the memory management behaviors of the corona.
Let’s say I’m going to make books for the kids.
And each page has a lot of PNGs and when they go to next page,
I need to remove all the PNGs , and add a lot of new PNGs for the new page.
But I noticed that when I go up the page , the memory usage is keep increasing.
So I wrote very very simple script in the main.lua
print(string.format( "memUsage = %.3f KB", collectgarbage( "count" ) ))
d= display.newGroup()
print(string.format( "memUsage = %.3f KB", collectgarbage( "count" ) ))
for i=1 ,2000, 1 do
local dispObj\_1 = display.newImageRect( "assets/song\_1/".."bg.jpg", 480, 360 )
dispObj\_1.x = 240
dispObj\_1.y = 160
dispObj\_1.xScale=1.0
dispObj\_1.yScale=1.0
d:insert(dispObj\_1)
dispObj\_1= nil
end
for i=d.numChildren, 1,-1 do
local x = d[i]
x.parent:remove(x)
x=nil
end
print(string.format( "memUsage = %.3f KB", collectgarbage( "count" ) ))
for i=1 ,2000, 1 do
local dispObj\_1 = display.newImageRect( "assets/song\_1/".."bg.jpg", 480, 360 )
dispObj\_1.x = 240
dispObj\_1.y = 160
dispObj\_1.xScale=1.0
dispObj\_1.yScale=1.0
d:insert(dispObj\_1)
dispObj\_1= nil
end
for i=d.numChildren, 1,-1 do
local x = d[i]
x.parent:remove(x)
x=nil
end
print(string.format( "memUsage = %.3f KB", collectgarbage( "count" ) ))
d.parent:remove(d)
d=nil
print(string.format( "memUsage = %.3f KB", collectgarbage( "count" ) ))
Very simple.
I put 2000 PNGs
and remove them.
and 2000 PNGs again.
and remove them again.
I’m expecting memory usage goes back where it started after removing them all,
but I’m getting the following result.
Is this normal behavior?
memUsage = 82.626 KB
memUsage = 82.771 KB
memUsage = 469.979 KB
memUsage = 900.267 KB
memUsage = 900.323 KB
[import]uid: 96678 topic_id: 17457 reply_id: 317457[/import]
[import]uid: 3826 topic_id: 17457 reply_id: 66234[/import]