a question about collectgarbage("count")

My app prints out the memory usage like this

local memUsage\_str = string.format( "MEMORY = %.3f KB", collectgarbage( "count" ) ) local textureMemUsed = system.getInfo("textureMemoryUsed") / (1024 \* 1024)

and the output is like this

I/Corona  (14741): MEMORY = 996.668 KB

I/Corona  (14741): TEXTURE used = 58.0615234375

My texture memory is now under control, but I found the MEMORY used by Lua (collectgarbage (“count”)) keeps increasing.

It is now at 1600-1800 KB, and I think it will keep going up if I keep using my app.

Is this normal? How far can it go? And at what point I should be cautious?

thanks.

If you’re using your app and the Lua memory usage keeps increasing and never flattens out, then your code has a memory leak. That’s definitely a problem – eventually you’ll run out of memory and your app will slow to a crawl or crash.  So you’ll need to find and plug the leak.

On the other hand, if you’re saying our Lua memory flattens out at 1600-1800 KB, that’s nothing to be concerned about.

  • Andrew

My app is like a RSS reader, so a user can keep flipping pages and the app keeps pulling content from the Internet.

The texture memory is not growing. I ensure all display objects are removed for old pages.

But the Lua memory is growing (not flattens out at 1600-1800 kb), I am just wondering what kind of code would increase Lua memory & what to be released. I have no idea about this.

Hi Joe,

Well if your texture memory isn’t growing, then the leak probably isn’t being caused by your handling of display objects.

One common cause of Lua memory leaks are timers and transitions.  If you assign a new timer or transition to a variable (which isn’t required, but if you do) then you have to set that variable to nil when the timer or transition completes.  The memory won’t be released simply when the timer or transition ends, you actually have to set the variable to nil to signal to the garbage collector that it’s garbage.

You mentioned your app keeps pulling content from the Internet.  You remove the display objects for old pages, but what about the rest of the page content?

Andrew

Thanks for your reminding. I didn’t remove other data for old pages because the user might flip back to them.

And after I traced more closely into the Lua memory used, I found it does not keep growing actually.

At some point, it comes down especially when I exit/destroy the scene.

If you’re using your app and the Lua memory usage keeps increasing and never flattens out, then your code has a memory leak. That’s definitely a problem – eventually you’ll run out of memory and your app will slow to a crawl or crash.  So you’ll need to find and plug the leak.

On the other hand, if you’re saying our Lua memory flattens out at 1600-1800 KB, that’s nothing to be concerned about.

  • Andrew

My app is like a RSS reader, so a user can keep flipping pages and the app keeps pulling content from the Internet.

The texture memory is not growing. I ensure all display objects are removed for old pages.

But the Lua memory is growing (not flattens out at 1600-1800 kb), I am just wondering what kind of code would increase Lua memory & what to be released. I have no idea about this.

Hi Joe,

Well if your texture memory isn’t growing, then the leak probably isn’t being caused by your handling of display objects.

One common cause of Lua memory leaks are timers and transitions.  If you assign a new timer or transition to a variable (which isn’t required, but if you do) then you have to set that variable to nil when the timer or transition completes.  The memory won’t be released simply when the timer or transition ends, you actually have to set the variable to nil to signal to the garbage collector that it’s garbage.

You mentioned your app keeps pulling content from the Internet.  You remove the display objects for old pages, but what about the rest of the page content?

Andrew

Thanks for your reminding. I didn’t remove other data for old pages because the user might flip back to them.

And after I traced more closely into the Lua memory used, I found it does not keep growing actually.

At some point, it comes down especially when I exit/destroy the scene.