Hey guys, I am using a performance meter (tells memory usage and fps) from Corona archives to diagnose some memory problems in my project:
http://developer.coronalabs.com/code/easy-use-performance-meter-memory-texture-memory-fps
I used a blank project to test this performance meter, and I noticed something confusing. The project starts at 200 kbs of system memory, however, even if i do nothing, the system memory will rise up to around 350 kbs of system memory in a few seconds, then suddenly drop back down to 200. This was a vicious cycle that continued until I terminated the program. I suspect that this may be a memory leak on the part of the performance meter? However, I could not find the source of the leak and I’m also confused what prompted the memory to drop back to normal.
Tldr Here are my questions:
1.What is causing the memory leak in the following code?
- Why is the system memory rising and falling cyclically (around every 1/2 minute) even when I’m not doing anything?
Here is the code to the simple performance meter:
[lua]
–THIS IS WORK AND CODE CREATED BY LERG FOR CORONA SDK/ LUA USE. I DID NOT ADD ANYTHING TO THIS BUT TO UPDATE THE MODULE FOR GFX2. ALL CREDIT GOES TO LERG FOR CREATING THE ORIGINAL CODE.
local _M = {}
local mFloor = math.floor
local sGetInfo = system.getInfo
local sGetTimer = system.getTimer
local prevTime = 0
_M.added = true
local function createText()
local memory = display.newText(‘00 00.00 000’,10,0, ‘Helvetica’, 18);
--memory:setFillColor(255,53,247)
memory:setFillColor(1,1,1,1)
memory.anchorY = 1
memory.x, memory.y = display.contentCenterX, display.contentHeight - 5
function memory:tap ()
collectgarbage(‘collect’)
if _M.added then
Runtime:removeEventListener(‘enterFrame’, _M.labelUpdater)
_M.added = false
memory.alpha = .5
else
Runtime:addEventListener(‘enterFrame’, _M.labelUpdater)
_M.added = true
memory.alpha = 1
end
end
memory:addEventListener(‘tap’, memory)
return memory
end
function _M.labelUpdater(event)
local curTime = sGetTimer()
_M.text.text = tostring(mFloor( 1000 / (curTime - prevTime))) … ’ ’ …
tostring(mFloor(sGetInfo(‘textureMemoryUsed’) * 0.0001) * 0.01) … ’ ’ …
tostring(mFloor(collectgarbage(‘count’)))
_M.text:toFront()
prevTime = curTime
end
function _M:newPerformanceMeter()
self.text = createText(self)
Runtime:addEventListener(‘enterFrame’, _M.labelUpdater)
end
return _M
[/lua]