Corona SDK Pro Tip of the Day #12
Memory consumption

View memory consumption with a press of a single button! Or maybe two buttons...

The idea is similar to my previous pro tip. We bind one button to show current memory usage and another button to perform garbage collection.

It is useful to see if you have any memory leaks, it doesn't occupy any space on the screen or flood the terminal output with lots of messages as many other memory profiling scripts do.

Just press a button in any time and see what's happening.

Runtime:addEventListener('key', function (event)  
    if event.phase == 'down' then
        if event.keyName == 'g' then
            collectgarbage('collect')
        elseif event.keyName == 'm' then
            local memoryUsed = collectgarbage('count')
            local textureMemoryUsed = system.getInfo('textureMemoryUsed') / 1048576
            print('System Memory:', string.format('%.00f', memoryUsed) .. ' kB')
            print('Texture Memory:', string.format('%.03f', textureMemoryUsed) .. ' MB')
        end
    end
end)  

G for garbage collect, M for printing memory usage.

You can combine it with the screenshot saving action.

Binding buttons to some actions is useful for development, you can switch physic's draw mode, restart a level, enable cheats, go to next level, make a level editing and so on. I use it all the time.

Indie Game Developer