I have one scene I’m testing that’s relatively simple. I’ve gone through the tutorial on optimization and garbage collection.
It consists of a player throwing bombs at other objects - and they both die (remove then nil) soon after collision.
I’m running this code to test for leaks:
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 )
Now it all works handy dandy but my question is once you are in the scene - is it normal for MEMORY to slowly increase when you perform an action and not go back down once action is complete?
In my example, a character spawns a bomb when you touch screen - toss - hits an object. Then both the object and bomb blow up then get removed.
My logic would lead me to believe that the memory would increase a little then once I remove the two objects, memory count will go back down. But that’s not the case for me - am I experiencing memory Leak or misinterpreting how Memory is used?
Below is the garbage collection code results when I’m spawning/tossing bombs and they collide - remove the bomb and whatever it collides with.
MEMORY = 495.419 KB TEXTURE = 2.7714881896973
MEMORY = 495.864 KB TEXTURE = 2.7714881896973
MEMORY = 496.841 KB TEXTURE = 2.7714881896973
MEMORY = 496.632 KB TEXTURE = 2.7714881896973
MEMORY = 496.397 KB TEXTURE = 2.7558631896973
MEMORY = 498.450 KB TEXTURE = 2.7714881896973
MEMORY = 499.708 KB TEXTURE = 2.7714881896973
MEMORY = 499.890 KB TEXTURE = 2.7714881896973
MEMORY = 500.856 KB TEXTURE = 2.7714881896973
The Memory will keep counting up even when I remove the two objects (bomb and what its colliding with) and make them Nil. I thought that memory would eventually go back down once the bomb and object collide since I’m removing them.
NOTE - And IF I stop throwing bombs - then the Memory Count will remain at the last value, not increasing.
IF I keep throwing bombs - the Memory keeps increasing despite them being removed along with the objects they collide with. IF I don’t throw bombs then memory will remain the same.