collectgarbage( "count" ) is different from memory used by the game in android application manager

Hello all.

I followed each and every tip in this forum to prevent my game from leaking memory and I tought I could do it.

I use the following code snippet, that I found somewhere here in the forum, to show the current memory used:

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 )  

First the memory and texture rises constantly to a maximum of about

memory = 1500.000 kb texture = 14

while playing.

(While testing with a huge amount of display objects running around, way more than the game will actually use. (Normal use is about 1200 kb memory))

When I return to my main menu, the memory falls down to a stable value.

If I repeat this many times, like: main --> playing the game --> main --> playing the game --> main, …

it always return to the same values for memory and texture.

Now the problem is, that if I go to the android application manager the RAM used by the game is constantly rising. It starts at about 30 mb and after some time I am at 200 mb, rising further.

This is not good, because this slows the game down, by the time although collectgarbage( “count” ) says, I am using the same memory than in the beginning.

Does somebody know why the values from collectgarbage( “count” ) are different from the actual values or has same problems and know how to solve them?

Or am I wrong and I missunderstand something?

Thanks in advance,

Felix

The memory reflected in the App manager might be referring to application or Lua memory; the texture memory just relates to the graphics objects, not the actual operations that the device is going through to run the app itself. 

Here’s Lerg’s performance meter updated for G2 that will show a running tally of stats for your app. It should give you a better view into what assets are taking of how much memory.

HTH

Thank you Panc Software (HTH?) for your reply.

The recomended performance meter does the same than the code that I use. I have additionally the fps.lua from another forum post in my game to show the fps, if required.

The problem is, how to figure out what causes the increasing RAM if corona does not know that the RAM is increasing?

Or am I confusing something? I thought the RAM shown in the Task manager IS the lua memory, or at least related to it.

HTH means “Hope This Helps” :wink:

Lerg’s performance meter shows the FPS, the texture mem and Lua mem with the math.floor helper and displays it in the app itself, which gives a bit more vision into what *might* be causing the memory leaks. Running it without math.floor and in the simulator is fine, but it sounds like you’re encountering issues with running on device, so I thought Lerg’s module might be helpful.

You might actually be causing the problem, just by running your homegrown memory module. The “collect” feature of the collectGarbage api is quite labor-intensive, and running it every frame, or every second, or even every 5 seconds, might chew up the memory for your app, and if each call gets backed up behind each other, Boom, you’ve got yourself a bottleneck.

I’d start by taking out the “collect” call and see if that does anything. Again, Lerg’s module isn’t a necessity, but it might make your performance metering a bit more user-friendly.

didn t know this abbrevitation “HTH”, good to know :slight_smile:

I do have the problems on device.

I use adb logcat to see the lua memory and the grafic memory on the computer while playing. 

Other then that, lergs module would be great to monitor this values.

I print the mem values every second to the console and so I can compare the values over time.

So I see that the value of collectgarbage( “count” ) gets more in the begining but then reaches a point where it stays the same even after 10 times main–>playinggame–>main .

But the RAM usage in the task manager increases every time about 10 mb.

I give it a try, and remove the collect call, but in my puplic version of the game, I removed this part completly and I got some review that the game is getting slower after intense playing. So I think this is not the problem.

Anyway,

thank you a lot for your suggestions :slight_smile:

Completely understood. I like Lerg’s module because it replicates as close to a true consumer use environment as possible (no logcat, no extra print statements, no console printing etc…). Different tools for different folks, for sure. 

Let me know how you get on. I’m interested in the outcome; if you let me know the app name, I can download and test it as well for a little additional feedback.

I tried it now without the collectgarbage part and this did not change the result.

But what I saw is that my game has a stadily increasing memory consumption. after some time the auto garbage collection cleans the memory and it starts again rising.

This is very weird and I need to further investigate this, because this even happens when the game is in the opening state, ie. when it is loaded and waits for the user to tap the screen.

Actually, I saw now, that the RAM is rising constantly as soon as the game is started, although the code that I posted in the first post shows a constant value of the memory… :frowning:

I would be happy about some feedback, you can find my game here:

https://play.google.com/store/apps/details?id=de.web.butzbach.felix.bucketman

I am stil working hard on it, and there will be an update soon, where I want to cure this memory problem.

I would be happy about some feedback.

I planed to show my app to the corona comunity after the next update, but hey, this could be a preview :slight_smile:

I’d love to take a look. I would be able to provide better feedback if you could make me an Android build with the memory module implemented, so I can see where exactly the memory is increasing and being deleted. If you’d rather not do that, I understand, but it might be the best way to get to the bottom of your issue.

Thanks for this offer.

I will get in personal contact via private message.

Whereas it is easy visible that there is a problem if you just switch to the task manager time by time while the game is in the main menu without doing anything.

I will investigate this now…

always something, grml…

I investigated this now furhter and it seems that always when I go out of a game into the task manager and than back, the Ram consumed by the game increases. always!

The amount is dependent on the number and size of images currently on the screen.

This even works with the hello world example.

It starts with about 13 mb ram and after some changes between task manager and hello world programm, the ram is on my phone at about 30 mb …

its going up and down, rises sometimes more and sometimes less, but it keeps rising in the big picture…

For my game that made an increase of about 20 mb everytime I switched between game and taskmanager.

I tried this with other games (not made with corona, I think) and this did not happen, ie. the consumed ram does not increase constantly.

I also tried it with “Crosstown Smash (free)” and there (in the select world menu) the ram rises constantly too. (always just about 3 mb, but everytime) …

I will stop now with this and hope that my other fixes reduce the lag in higher levels enough to this becomes not a problem…

edit: after some time the Ram reduces back to the initial value, at least at the hello world example. (More then 20 minutes)

Sounds like I have some leaks to plug!

I don’t think I ever saw that leak. But then again, I was going by Lergs metering and not the task manager. D you see the memory increase in the Hello World app when using the performance meter as well?

I dont think its worth the time, especially because after some time the RAM used by the game is reduced automatically, probably by the OS…

I did not try the performance meter in the hello world app. I wnated to have it as natural as possible :slight_smile:

The memory reflected in the App manager might be referring to application or Lua memory; the texture memory just relates to the graphics objects, not the actual operations that the device is going through to run the app itself. 

Here’s Lerg’s performance meter updated for G2 that will show a running tally of stats for your app. It should give you a better view into what assets are taking of how much memory.

HTH

Thank you Panc Software (HTH?) for your reply.

The recomended performance meter does the same than the code that I use. I have additionally the fps.lua from another forum post in my game to show the fps, if required.

The problem is, how to figure out what causes the increasing RAM if corona does not know that the RAM is increasing?

Or am I confusing something? I thought the RAM shown in the Task manager IS the lua memory, or at least related to it.

HTH means “Hope This Helps” :wink:

Lerg’s performance meter shows the FPS, the texture mem and Lua mem with the math.floor helper and displays it in the app itself, which gives a bit more vision into what *might* be causing the memory leaks. Running it without math.floor and in the simulator is fine, but it sounds like you’re encountering issues with running on device, so I thought Lerg’s module might be helpful.

You might actually be causing the problem, just by running your homegrown memory module. The “collect” feature of the collectGarbage api is quite labor-intensive, and running it every frame, or every second, or even every 5 seconds, might chew up the memory for your app, and if each call gets backed up behind each other, Boom, you’ve got yourself a bottleneck.

I’d start by taking out the “collect” call and see if that does anything. Again, Lerg’s module isn’t a necessity, but it might make your performance metering a bit more user-friendly.

didn t know this abbrevitation “HTH”, good to know :slight_smile:

I do have the problems on device.

I use adb logcat to see the lua memory and the grafic memory on the computer while playing. 

Other then that, lergs module would be great to monitor this values.

I print the mem values every second to the console and so I can compare the values over time.

So I see that the value of collectgarbage( “count” ) gets more in the begining but then reaches a point where it stays the same even after 10 times main–>playinggame–>main .

But the RAM usage in the task manager increases every time about 10 mb.

I give it a try, and remove the collect call, but in my puplic version of the game, I removed this part completly and I got some review that the game is getting slower after intense playing. So I think this is not the problem.

Anyway,

thank you a lot for your suggestions :slight_smile:

Completely understood. I like Lerg’s module because it replicates as close to a true consumer use environment as possible (no logcat, no extra print statements, no console printing etc…). Different tools for different folks, for sure. 

Let me know how you get on. I’m interested in the outcome; if you let me know the app name, I can download and test it as well for a little additional feedback.

I tried it now without the collectgarbage part and this did not change the result.

But what I saw is that my game has a stadily increasing memory consumption. after some time the auto garbage collection cleans the memory and it starts again rising.

This is very weird and I need to further investigate this, because this even happens when the game is in the opening state, ie. when it is loaded and waits for the user to tap the screen.

Actually, I saw now, that the RAM is rising constantly as soon as the game is started, although the code that I posted in the first post shows a constant value of the memory… :frowning:

I would be happy about some feedback, you can find my game here:

https://play.google.com/store/apps/details?id=de.web.butzbach.felix.bucketman

I am stil working hard on it, and there will be an update soon, where I want to cure this memory problem.

I would be happy about some feedback.

I planed to show my app to the corona comunity after the next update, but hey, this could be a preview :slight_smile:

I’d love to take a look. I would be able to provide better feedback if you could make me an Android build with the memory module implemented, so I can see where exactly the memory is increasing and being deleted. If you’d rather not do that, I understand, but it might be the best way to get to the bottom of your issue.

Thanks for this offer.

I will get in personal contact via private message.

Whereas it is easy visible that there is a problem if you just switch to the task manager time by time while the game is in the main menu without doing anything.

I will investigate this now…

always something, grml…