Thank you for the composer info.
I did use it and couldn’t find anything wrong BUT I afterwards was able to circle a function which was behaving differently on simulator and device. When looking into it I noticed there maybe are some graphics created which are not deleted properly with scene change.
I first found this strange because if so, this should be a problem on both the simulator AND on device, right? So I created a function for deleting the graphics before scene change to make sure. Testing this still showed a difference on the device, so I looked closer and found this:
I was using text display objects I created like this using the graphic image and created them “on” the image itself:
local gfx={} local groups={group} local createimages=function() gfx.btn\_nextLVL=display.newImage("myimage.png",256,256) gfx.btn\_nextLVL.theTextShadow=display.newText(options) gfx.btn\_nextLVL.theText=display.newText(options) -- put all in a group groups.group=display.newGroup() groups.group:insert(gfx.btn\_nextLVL) groups.group:insert(gfx.btn\_nextLVL.theTextShadow) groups.group:insert(gfx.btn\_nextLVL.theText) end
I later removed the graphics with a scene change by calling a function which is doing this:
for k,v in pairs( gfx ) do if v then display.remove ( v ) v=nil if gfx[k] then display.remove (gfx[k]) gfx[k]=nil end end if #gfx then for x=#gfx,1,-1 do if gfx[x] then display.remove(gfx[x]) gfx[x]=nil end end end end for k,v in pairs( groups ) do if v then display.remove ( v ) v=nil if groups[k] then display.remove (groups[k]) groups[k]=nil end end if #groups then for x=#groups,1,-1 do if groups[x] then display.remove(groups[x]) groups[x]=nil end end end end
This seems to work on the simulator BUT not on the device because it seems (after testing) the memory for the text objects is not removed correctly on the device. When doing this for example (shown for a specific button image) for all images which are using this kind of display.newText objects:
if gfx.btn\_nextLVL then if gfx.btn\_nextLVL.theTextShadow then display.remove(gfx.btn\_nextLVL.theTextShadow) gfx.btn\_nextLVL.theTextShadow=nil end if gfx.btn\_nextLVL.theText then display.remove(gfx.btn\_nextLVL.theText) gfx.btn\_nextLVL.theText=nil end display.remove(gfx.btn\_nextLVL) gfx.btn\_nextLVL=nil end
This will remove more memory on device than it did before without this lines!
Is this possible? Can someone please test this and confirm?
I’m right now looking through all my code for this kind of added display.objects (text and other) to get my system memory leak removed. A big part already is now!
But the big question remains: Why is this only happening on device and not the simulator?