Memory not cleared ?

Hi there,

I have made a simple testing to see whether did i clear the memory correctly. 

first I created a group.

second, created a picArr empty table for later use.

local terrLayer = display.newGroup() local picArr = {}

so next, I created timer with function to do a loop to place png onto the screen for 10000 times because I wanted to see the huge difference in memory. And another function which will happen in 8 secs after running code, to “clear”/remove all of the pictures.

local function createAll()       for a=1, 10000 do           picArr[a] = display.newImage(terrLayer, "example.png")       end end timer.performWithDelay(3000, createAll ) local function delAll()          terrLayer:removeSelf()          terrLayer = nil          picArr = nil end timer.performWithDelay(8000, delAll )

And as usual , a memory print code below.

local function checkMemory()      collectgarbage( "collect" )      local memUsage\_str = string.format( "MEMORY = %.3f KB", collectgarbage( "count" ) )      print( memUsage\_str, "TEXTURE = "..(system.getInfo("textureMemoryUsed") / (1024 \* 1024) ) )   end   timer.performWithDelay( 1000, checkMemory, 0 )

(i will omit the texture memoryused because it was cleared nicely after delAll function)

Results of execution:

(Start of application)  Memory = 222 kb

3000ms aftermath

(calls func createAll)  Memory = 2650 kb

5000ms aftermath
(calls func delAll)      Memory = 477 kb
 

Supposedly, everything I previously created for the picture was removed and nil-ed , whats left is the checkMemory Timer, which couldnt be 477-222=255 kb worth of memory right? 

what is it causing the extra memory that shoots it up to 477 kb (compared to the start of application 222kb)

I really need answers to this, so that I can safely clear everything correctly.

Hi @zaviermars,

It’s actually typical that your memory will climb slightly from its level at the very start of the app, and then “level off” around that slightly higher threshold going forth. So, this isn’t a reason to worry, unless you do further memory checks and you notice that the memory continues to climb and climb above the ~477 point. If that occurs, you probably have a memory leak somewhere.

Best regards,

Brent

Hi @zaviermars,

It’s actually typical that your memory will climb slightly from its level at the very start of the app, and then “level off” around that slightly higher threshold going forth. So, this isn’t a reason to worry, unless you do further memory checks and you notice that the memory continues to climb and climb above the ~477 point. If that occurs, you probably have a memory leak somewhere.

Best regards,

Brent