I stripped everything out of main.lua, menu.lua, levels.lua and options.lua except for essentials. I placed it in “test project” folder, along with PNG folder with three images (background image for menu.lua, and a button – a regular and over state).
In the “test project” folder, I also included director.lua (v1.3) and ui.lua(v1.5) that I use in my game project. I also copied build.settings, config.lua and icons from SampleCode/Ads/InMobi folder.
In this test project folder, main.lua looks like this:
display.setStatusBar( display.HiddenStatusBar ); --Hide status bar from the beginning
local director = require("director");
local ui = require("ui");
local mainGroup = display.newGroup();
local function main()
mainGroup:insert(director.directorView) ;
director:changeScene("menu", "crossfade");
return true;
end
main();
print( "\>\>\>\>\> hit the last line of the MAIN lua code" )
collectgarbage()
print( "MemUsage (in KB): " .. collectgarbage("count") )
system.getInfo( "textureMemoryUsed" )
print( "textureMemoryUsed is " .. system.getInfo( "textureMemoryUsed" ) )
menu.lua looks like this:
module(..., package.seeall);
function new()
local menuGroup = display.newGroup();
local bgMenu = display.newImage("PNG/img\_Menu.png", -20, 0, true);
function changeScene(event)
director:changeScene(event.target.scene, "flip");
end
local btn\_Level = ui.newButton{
defaultSrc = "PNG/btnBlue.png", defaultX = 200, defaultY = 60,
overSrc = "PNG/btnBlueOver.png", overX = 200, overY = 60,
text = "LEVELS",
size = 20,
font = "Helvetica-Bold",
textColor = { 255, 255, 255, 255 },
onRelease = changeScene,
emboss = true
}
btn\_Level.x = 160;
btn\_Level.y = 175;
local btn\_options = ui.newButton{
defaultSrc = "PNG/btnBlue.png", defaultX = 200, defaultY = 60,
overSrc = "PNG/btnBlueOver.png", overX = 200, overY = 60,
text = "OPTIONS",
size = 20,
font = "Helvetica-Bold",
textColor = { 255, 255, 255, 255 },
onRelease = changeScene,
emboss = true
}
btn\_options.x = btn\_Level.x;
btn\_options.y = btn\_Level.y + 65;
btn\_Level.scene = "levels";
btn\_options.scene = "options";
menuGroup:insert(bgMenu);
menuGroup:insert(btn\_Level);
menuGroup:insert(btn\_options);
print( "\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\>\> hit the last line of MENU.lua" )
--collectgarbage()
timer.performWithDelay( 1, function() collectgarbage(); end, 1)
print( "MemUsage (in KB): " .. collectgarbage("count") )
system.getInfo( "textureMemoryUsed" )
print( "textureMemoryUsed is " .. system.getInfo( "textureMemoryUsed" ) )
return menuGroup;
end
levels.lua looks like this:
module(..., package.seeall);
function new()
local levelGroup = display.newGroup();
function changeScene(event)
director:changeScene(event.target.scene, "flip");
end
local goBack = ui.newButton{
defaultSrc = "PNG/btnBlue.png", defaultX = 200, defaultY = 60,
overSrc = "PNG/btnBlueOver.png", overX = 200, overY = 60,
text = "BACK TO MENU",
size = 20,
font = "Helvetica-Bold",
textColor = {255, 255, 255, 255},
onRelease = changeScene,
emboss = true
}
goBack.x = 160;
goBack.y = 240;
goBack.scene = "menu";
levelGroup:insert(goBack);
print( "\>\>\>\>\> hit the last line of LEVELS.lua reached" )
--collectgarbage()
timer.performWithDelay( 1, function() collectgarbage(); end, 1)
print( "MemUsage (in KB): " .. collectgarbage("count") )
system.getInfo( "textureMemoryUsed" )
print( "textureMemoryUsed is " .. system.getInfo( "textureMemoryUsed" ) )
return levelGroup;
end
And finally, options.lua looks like this:
module(..., package.seeall);
function new()
local optionsGroup = display.newGroup();
function changeScene(event)
director:changeScene(event.target.scene, "flip");
end
local goBack = ui.newButton{
defaultSrc = "PNG/btnBlue.png", defaultX = 200, defaultY = 60,
overSrc = "PNG/btnBlueOver.png", overX = 200, overY = 60,
text = "BACK TO MENU",
size = 20,
font = "Helvetica-Bold",
textColor = {255, 255, 255, 255},
onRelease = changeScene,
emboss = true
}
goBack.x = 160;
goBack.y = 240;
goBack.scene = "menu";
optionsGroup:insert(goBack);
print( "\>\>\>\>\> hit the last line of OPTIONS.lua reached" )
--collectgarbage()
timer.performWithDelay( 1, function() collectgarbage(); end, 1)
print( "MemUsage (in KB): " .. collectgarbage("count") )
system.getInfo( "textureMemoryUsed" )
print( "textureMemoryUsed is " .. system.getInfo( "textureMemoryUsed" ) )
return optionsGroup;
end
When I run it in simulator, here’s what I get on terminal. Does this look like memory is leaking, or it really isn’t leaking? What do you think? Before I build dozens of levels for my game, it would be nice if I can understand what I’m seeing and be assured that I probably do not need to redo each level later on:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> hit the last line of MENU.lua
MemUsage (in KB): 121.6123046875
textureMemoryUsed is 1204224
>>>>> hit the last line of the MAIN lua code
MemUsage (in KB): 114.0478515625
textureMemoryUsed is 1204224
>>>>> hit the last line of OPTIONS.lua reached
MemUsage (in KB): 263.6513671875
textureMemoryUsed is 1228800
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> hit the last line of MENU.lua
MemUsage (in KB): 129.5283203125
textureMemoryUsed is 1228800
>>>>> hit the last line of LEVELS.lua reached
MemUsage (in KB): 131.3125
textureMemoryUsed is 1228800
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> hit the last line of MENU.lua
MemUsage (in KB): 131.98828125
textureMemoryUsed is 1228800
>>>>> hit the last line of LEVELS.lua reached
MemUsage (in KB): 134.4599609375
textureMemoryUsed is 1228800
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> hit the last line of MENU.lua
MemUsage (in KB): 131.35546875
textureMemoryUsed is 1228800
>>>>> hit the last line of OPTIONS.lua reached
MemUsage (in KB): 127.5078125
textureMemoryUsed is 1228800
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> hit the last line of MENU.lua
MemUsage (in KB): 132.41015625
textureMemoryUsed is 1228800
[import]uid: 67217 topic_id: 4715 reply_id: 51494[/import]