Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Acceptable Memory Usage?
Started by mrgoose Jan 07 2012 05:33 PM

- - - - -
37 replies to this topic
[TOPIC CONTROLS]
Page 1 of 2 1 2
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

mrgoose

[GLOBAL: userInfoPane.html]
mrgoose
  • Enthusiast

  • 31 posts
  • Corona SDK

Doing a little optimization and am wondering what level of memory usage is considered "acceptable".

Is there a some kind of guideline to refer to, to prevent tapping out a specific device?

I suppose I'm looking for a chart that states something like:

Max memory allowed by an app by device:
iPhone: LUA: 2MB / Texture: 12MB
iPad: LUA: 4MB / Texture: 32MB
Android: LUA: 3MB / Texture: 32MB
Nook: LUA: 2MB / Texture: 8MB

... and how does this match up with Lua's feature of reporting memory usage using:

collectgarbage()
print( "MemUsage: " .. collectgarbage("count") .. " KB" )
print( "textureMemoryUsed: " .. (system.getInfo( "textureMemoryUsed" )/1000000) .. " MB" )

For example, during run-time, my app is currently leveling off at:

MemUsage: 771.3876953125 KB
textureMemoryUsed: 10.807296 MB

So how do these numbers correspond to maximum levels allowed / tolerated by devices?
uid: 616 topic_id: 20090 reply_id: 320090


[TOPIC: post.html]
#2

peach pellen

[GLOBAL: userInfoPane.html]
peach pellen
  • Corona Geek

  • 8,866 posts
  • Alumni

There isn't a chart like this that I am aware of, sorry.

The main issue I've seen people encounter is on Android, where texture memory limits seem to vary a lot - and on the iPhone3GS where you want to keep texture memory below 25MB.

In my (limited) experience it seems like if you can keep texture memory usage under about 20MB you are unlikely to encounter any issues.

Peach :)
uid: 52491 topic_id: 20090 reply_id: 78474


[TOPIC: post.html]
#3

@RSCdev

[GLOBAL: userInfoPane.html]
@RSCdev
  • Corona Geek

  • 1,489 posts
  • Corona SDK

Sorry @mrgoose to be posting into your topic, but I do have the same question as you and so I would like to ask Mrs. Peach how about the LUA Memory?

Does exist somewhere any table telling us more about this subject?
Thanks in advance,
Cheers,
Rodrigo.
uid: 89165 topic_id: 20090 reply_id: 78476


[TOPIC: post.html]
#4

mightE

[GLOBAL: userInfoPane.html]
mightE
  • Contributor

  • 187 posts
  • Corona SDK

Can not say if true.
"Actually, once you start using over 10mb the iphone starts closing apps and once you hit much over 12mb the OS will close your app."
http://www.iphonedevsdk.com/forum/iphone-sdk-development/1372-memory-usage.html#post9038
uid: 79135 topic_id: 20090 reply_id: 78479


[TOPIC: post.html]
#5

PiotrT

[GLOBAL: userInfoPane.html]
PiotrT
  • Contributor

  • 163 posts
  • Corona SDK

My game is working perfectly fine (iPhone4) when memory usage is about max 500.234234 but when memory usage is about 550 and higher the game slows down ???
Texture Memory is about plus minus 10-14 MB
Is it normal ?

but maybe is TextureMemory problem ??
uid: 13156 topic_id: 20090 reply_id: 78484


[TOPIC: post.html]
#6

@RSCdev

[GLOBAL: userInfoPane.html]
@RSCdev
  • Corona Geek

  • 1,489 posts
  • Corona SDK

Thank you @anddrewscott. I appreciate the info shared.
uid: 89165 topic_id: 20090 reply_id: 78582


[TOPIC: post.html]
#7

peach pellen

[GLOBAL: userInfoPane.html]
peach pellen
  • Corona Geek

  • 8,866 posts
  • Alumni

Andrew's link is very useful :)

Pitor, that texture memory is fine on an iPhone 4, although if you have a lot else running it might make a difference.

Peach :)
uid: 52491 topic_id: 20090 reply_id: 78635


[TOPIC: post.html]
#8

PiotrT

[GLOBAL: userInfoPane.html]
PiotrT
  • Contributor

  • 163 posts
  • Corona SDK

Hi
Most of you probably know that , but in my case the problem wasn't with system memory or texture memory but with the code which measure this values.
In my game a lot is going on , a lot of objects are removing and creating all the time.
I was using this code
local lastCheck = {sysMem = 0, textMem = 0}
Runtime:addEventListener('enterFrame', function()
    -- watch for leaks
    collectgarbage()
	
    local sysMem = collectgarbage("count") * 0.001
    local textMem = system.getInfo( "textureMemoryUsed" )*0.000001

    if lastCheck.sysMem ~= sysMem or lastCheck.textMem ~= textMem then
        lastCheck.sysMem = sysMem
        lastCheck.textMem = textMem

        print ("mem: " .. math.floor(sysMem*1000)*0.001 .. "MB \t " .. math.floor(textMem*1000)*0.001 .. "MB")
    end

end)

When I remove it no slows down on Iphone 4
On the other hand maybe I am close to end of cpu power, because on Iphone 4s no slows even with this code working.
uid: 13156 topic_id: 20090 reply_id: 78681


[TOPIC: post.html]
#9

peach pellen

[GLOBAL: userInfoPane.html]
peach pellen
  • Corona Geek

  • 8,866 posts
  • Alumni

That's a good point Piotr - all debugging code should be removed for production/beta test builds unless still required.

Peach :)
uid: 52491 topic_id: 20090 reply_id: 78751


[TOPIC: post.html]
#10

ec2

[GLOBAL: userInfoPane.html]
ec2
  • Contributor

  • 130 posts
  • Corona SDK

A table like this would be extremely helpful for iOS and Android devices and it would be great if Ansca could compile such a list (as it's unlikely that an individual developer would have access to enough devices).

I have been developing an app that is quite demanding on texture memory. It is at 2MB memory and 47MB texture memory running on a 3GS without any problems. I did try to stress the 3GS a couple of weeks ago by going higher with texture memory and it still ran ok. Unfortunately I don't remember what level of texture memory I went up to since my main aim at the time was just to check that I had enough "headroom" and wasn't at the borderline of crashing the 3GS.

On an iPad 1, I'm at 2MB memory and 73MB texture memory. Again performance is fine and I did go higher just to check that I wasn't at a borderline condition but can't remember what I went up to.
uid: 29384 topic_id: 20090 reply_id: 78959


[TOPIC: post.html]
#11

@RSCdev

[GLOBAL: userInfoPane.html]
@RSCdev
  • Corona Geek

  • 1,489 posts
  • Corona SDK

Nice info @ec2.
uid: 89165 topic_id: 20090 reply_id: 78964


[TOPIC: post.html]
#12

mrgoose

[GLOBAL: userInfoPane.html]
mrgoose
  • Enthusiast

  • 31 posts
  • Corona SDK

Thanks ec2, looks like you've set the bar for iphone 3gs and ipad 1.

So far our "acceptable" table looks like:

                 LUA Memory    Texture Memory
iPhone 3gs       2 MB          47 MB
iPad 1           2 MB          74 MB
...

If it's not to much to ask to re-run those stress tests, then we can fill out the table with a "becomes unstable at" column.

Of course, I think a lot of this info would be considered subjective, since the type/size/alpha of graphics, style of coding, background apps, and how intensive the corona/lua "behind the scenes" stuff is called / loaded / running.

But at least we'll have some kind of a guideline to reference to see if we're in the ball park.
uid: 616 topic_id: 20090 reply_id: 79078


[TOPIC: post.html]
#13

@RSCdev

[GLOBAL: userInfoPane.html]
@RSCdev
  • Corona Geek

  • 1,489 posts
  • Corona SDK

Very gOOd information is going here guys. As more we post here about the "memory" subject as more we can get it "crushed". :)

BTW we have to take care and not forget that after ALL the Hardware, Software, System, etc factors, I believe we still must consider the own USER of the iDevice and so the app! Yes, that`s really hard part to tell about BUT imagine someone trying to run any app have gotten the iDevice taskbar bloated of other opened apps?!? WOW, it would make "our" app suffer because as we know: as more running apps (on background or not) it is "system" consuming as well IMHO.

So these info shared here are really good by "parameters" but not even very close to the "real situation". :\

Cheers,
Rodrigo.
uid: 89165 topic_id: 20090 reply_id: 79103


[TOPIC: post.html]
#14

Danny

[GLOBAL: userInfoPane.html]
Danny
  • Corona Geek

  • 2,597 posts
  • Corona Staff

Just like to chime in regarding above post that stated memory use of over 12mb would close your app.

This may or may not have been the case in the early days, but on 3gs and above (which is now the
Standard) this isnt the case.

I had a game using 120mb of memory with no issues, your milage may vary though. Anything under 100mb should be fine. You could probably get away with more too.
uid: 84637 topic_id: 20090 reply_id: 79137


[TOPIC: post.html]
#15

darkconsoles

[GLOBAL: userInfoPane.html]
darkconsoles
  • Contributor

  • 795 posts
  • Guests

If i use this function to monitor mem usage, what should i aim for as a highest point of memory?
local monitorMem = function()         collectgarbage("collect")        print( "\nMemUsage: " .. collectgarbage("count") )        local textMem = system.getInfo( "textureMemoryUsed" ) / 1000000        print( "TexMem: " .. textMem ) end


i dont know in what values its printed, in kilobytes maybe?
uid: 16142 topic_id: 20090 reply_id: 79146


[TOPIC: post.html]
#16

peach pellen

[GLOBAL: userInfoPane.html]
peach pellen
  • Corona Geek

  • 8,866 posts
  • Alumni

Hey Alexey,

That would print in MB.

Peach :)
uid: 52491 topic_id: 20090 reply_id: 79196


[TOPIC: post.html]
#17

darkconsoles

[GLOBAL: userInfoPane.html]
darkconsoles
  • Contributor

  • 795 posts
  • Guests

thanks Peach)
uid: 16142 topic_id: 20090 reply_id: 79214


[TOPIC: post.html]
#18

ec2

[GLOBAL: userInfoPane.html]
ec2
  • Contributor

  • 130 posts
  • Corona SDK

mrgoose,

Yes I'll do some more stress tests, probably at the weekend.

As you say, depending on the app, the limit of texture memory might vary slightly depending on what's happening elsewhere in the app. I'm handling 256x256 tiles as part of an app that displays maps and this requires creating new tiles and deleting old tiles as the user pans around the map.

I'll also try to do some tests on a Samsung Galaxy Tab 8.9" running Android 3.1.
uid: 29384 topic_id: 20090 reply_id: 79249


[TOPIC: post.html]
#19

mrgoose

[GLOBAL: userInfoPane.html]
mrgoose
  • Enthusiast

  • 31 posts
  • Corona SDK

As a bottom level base-line, looks like Corona is consuming about 80 KB just to get up and running.

Using the following in a blank folder with just a main.lua:

function checkMem()
	print( collectgarbage("count") )
end
Runtime:addEventListener("enterFrame", checkMem)

... first line is ~ 80 KB, then climbs to a peak of 160 before the garbage collections kicks in and starts re-couping memory.
e.g.
83.0234375
83.1552734375
83.2900390625
83.4248046875
83.5595703125
83.6943359375
83.8291015625
...
159.9375
160.0673828125
160.203125
160.3349609375
160.470703125
158.4052734375
158.541015625
158.67578125

The GC continues to do it's job and mem usage climbs down to about 90, then creeps back up to the 160 or more.

I suppose a timing mechanism (or when an array reach a cap or something like that) is part of the GC flow.

As I'm writing this post, I'm running the following:

local peak = 0
local ave = 0
local current = 0
local all = 0
local count = 1

local round = math.round
function checkMem()
	--collectgarbage()
	current = collectgarbage("count")
	
	if current > peak then peak = current end
	
	all = all + current
	ave = all / count
	count = count + 1
	
	print ("-------------")
	print ("p: " 	.. round(peak))
	print ("a: " 	.. round(ave))
	print ("c: " 	.. round(current))
	
end
Runtime:addEventListener("enterFrame", checkMem)
... and it looks like it's reporting:

-------------
p: 181
a: 136
c: 113

So, the bottom line is the Corona seems to consume an average of about 130 KB of memory as a "base level", with a peak of about 180 KB.

So perhaps as a rule of thumb, we can safely say the "base level average" for a bare minimum app is around 150 KB (keeping a little cushion and making it easier to remember).

NOTE: The code above has the collectgarbage() function commented out. This enables automatic GC to occur. If the function is not commented out, as in:

function checkMem()
	collectgarbage()
	current = collectgarbage("count")
...

Then i'm getting the following:
-------------
p: 77
a: 77
c: 77

... Which indicates that the baseline memory usage for Corona is actually right around 80 KB. (Similar to the startup usage as noted at the top of this post.

So the scripts available in this post are kind of "real world" numbers, as rarely will a developer manually cause GC.

Perhaps the Corona moderators can weigh in on this particular matter?

uid: 616 topic_id: 20090 reply_id: 79302


[TOPIC: post.html]
#20

@RSCdev

[GLOBAL: userInfoPane.html]
@RSCdev
  • Corona Geek

  • 1,489 posts
  • Corona SDK

Hey @mrgoose: Thumbs-Up! Excellent! Thank you.
Cheers,
Rodrigo.
uid: 89165 topic_id: 20090 reply_id: 79346


[TOPIC: post.html]
#21

mrgoose

[GLOBAL: userInfoPane.html]
mrgoose
  • Enthusiast

  • 31 posts
  • Corona SDK

Here is an interesting article concerning crashes due to not dealing with garbage collection:

http://jonbeebe.tumblr.com/post/2090082695/faster-garbage-collection-with-corona
uid: 616 topic_id: 20090 reply_id: 79822


[TOPIC: post.html]
#22

@RSCdev

[GLOBAL: userInfoPane.html]
@RSCdev
  • Corona Geek

  • 1,489 posts
  • Corona SDK

@mrgoose, sincerely wonderful blog`s post of @JonathanBebee. Great Reading as well. Thanks for that one too.

PS: Nothing better than good rules for optimization. ;)
Cheers,
Rodrigo.
uid: 89165 topic_id: 20090 reply_id: 79872


[TOPIC: post.html]
#23

ec2

[GLOBAL: userInfoPane.html]
ec2
  • Contributor

  • 130 posts
  • Corona SDK

I've now done a few tests. The versions below are in increasing order of texture memory requirement. All figures are for texture memory. iOS devices are running latest 5.0.1, "ipad" is 1st gen iPad, and "tab" is a Samsung Galaxy Tab 8.9 running Android 3.1.

Version 1
3gs: 89MB, sluggish response but doesn't exit
ipad: 92MB, runs fine
tab: 97MB, runs fine

Version 2
3gs: 102MB, sluggish response but doesn't exit
ipad: exits
tab: 110MB, runs fine

Version 3
3gs: exits
ipad: exits
tab: 136MB, runs fine

For my app, the limit for my iOS devices is about 100MB. Although the 3GS runs the app, at 89MB, it is clearly struggling and its response is poor. The Samsung tablet looks great as it is still happy when the others have given up.
uid: 29384 topic_id: 20090 reply_id: 80057


[TOPIC: post.html]
#24

PiotrT

[GLOBAL: userInfoPane.html]
PiotrT
  • Contributor

  • 163 posts
  • Corona SDK

Hi ec2
What about system memory for this texture values ? Did you test it ?
uid: 13156 topic_id: 20090 reply_id: 80632


[TOPIC: post.html]
#25

ec2

[GLOBAL: userInfoPane.html]
ec2
  • Contributor

  • 130 posts
  • Corona SDK

Hi PiotrT,
For all the versions, the amount of normal memory used is 2MB. I did not change it.
uid: 29384 topic_id: 20090 reply_id: 80738



[topic_controls]
Page 1 of 2 1 2
 
[/topic_controls]