RAM usage

Moderator
Posts: 704
Joined: 2002.04
Post: #1
Greetings, I'm trying to diagnose a crashing app, a crash I believe is being caused by too great RAM usage; the crash log reports exception types of EXC_BAD_ACCESS (SIGBUS) and EXC_BAD_ACCESS (SIGSEGV).

The app crashes on:
  • 2G iPod touch (iOS 4.x)
  • 4G iPod touch

The app does not crash on:
  • 2G iPod touch (iOS 2.x)
  • 3G iPod touch (iOS 3.x)
  • iPhone 4

Xcode's Debugger isn't providing any helpful information, but Instrument's Activity Monitor reports that (on the 3G iPod touch/iOS 3.x) the app stabilises at using 38Mb of RAM, and at the time of crashing (on the 2G iPod touch/iOS 4.x) the app is using 29Mb of RAM. According to this thread, both of those RAM usage figures are too great; depending on which poster you prefer to believe, it is a risk to stray above using 12Mb or 24Mb of RAM; which of these RAM usage figures (if either?) is correct?

Would it be a safe assumption that the larger RAM footprint of iOS 4.x is causing a crash on a device which has the same or a greater amount of RAM? (Eg. the 4G iPod touch compared to the 3G iPod touch/iOS 3.x or to the 2G iPod touch/iOS 2.x) - which would explain why the app crashes on the 4G iPod touch but not on the very-similar-but-twice-the-RAM iPhone 4. As I would rather not rearrange the app's memory allocations only to discover that the app still crashes due to misdiagnosing the cause of the crash Cry

Mark Bishop
--
Student and freelance OS X & iOS developer
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #2
(Oct 17, 2010 03:37 PM)sealfin Wrote:  According to this thread, both of those RAM usage figures are too great; depending on which poster you prefer to believe, it is a risk to stray above using 12Mb or 24Mb of RAM; which of these RAM usage figures (if either?) is correct?

I'd say staying under 24 MB is probably safe on all devices. We try to stay <= 20 to be on the safe side of that, in case we want to squeeze in another feature down the road.

On 2G and higher, eh, I don't have enough data to say for sure, but I'd guess you'd be fine at up to 40 MB. Especially the Retina devices because they know you'll be using 4x the graphics so they added more RAM. We've tested up to about 40 MB on Retina without any hassles yet.

Are you receiving a memory warning? If so, make sure you didn't lose a view behind your back because that's a fantastic way to crash when you try to access something that isn't there anymore. Be sure to simulate a memory warning on the simulator to see if that points you in the right direction.

I'm surprised you aren't able to catch the bad access with the debugger. Could it be a thread problem? If you're using Display Link, try switching temporarily to a timer instead to see if the crash goes away. [edit] now that I think about it, threading shouldn't be a problem on iOS devices because they aren't multi-processing, so scratch that suggestion.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #3
(Oct 17, 2010 05:03 PM)AnotherJake Wrote:  [edit] now that I think about it, threading shouldn't be a problem on iOS devices because they aren't multi-processing, so scratch that suggestion.

?? While you don't have multiple CPUs, you still run into the same problems with locking as it does have preemptive multithreading. On the other hand, I'm quite certain that a CADisplayLink calls back through the run loop on the main thread which is the same behaviour as a NSTimer.

I don't remember exactly what happens when you run low on RAM, but iirc it kills your process off before it ever returns a failed memory allocation to you.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #4
(Oct 17, 2010 05:37 PM)Skorche Wrote:  ?? While you don't have multiple CPUs, you still run into the same problems with locking as it does have preemptive multithreading.

Really? I didn't realize that would be a problem. In that case, un-scratch my scratched idea that threading matters.

I don't know about CADisplayLink on iOS, but CVDisplayLink on Mac most definitely does not come through on the main thread, I can guarantee you that. In fact, the one good way I know how to kernel panic my Mac is if I forget to lock my gl context before touching it from Cocoa on the main thread.

(Oct 17, 2010 05:37 PM)Skorche Wrote:  I don't remember exactly what happens when you run low on RAM, but iirc it kills your process off before it ever returns a failed memory allocation to you.
I seem to recall this as well.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #5
Pretty sure CADisplayLink does call back on the main thread.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #6
Well, you have to explicitly add it to a run loop as a timer source. Run loops run on a single thread, so I can't imagine it's starting a new thread for it.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #7
I didn't even think about that. You're right, on iOS it's probably on the main thread because it's (most likely) attached to the current runloop when you set it, which is most practically going to be from within a method called in the main thread. I suppose you could set it on a runloop in a different thread, but I can't imagine what good that would be.
Quote this message in a reply
Member
Posts: 81
Joined: 2007.07
Post: #8
There is no way you are even close the memory limits. I am using 50MB on all devices without problems, only 1g/2g you should be good with 60mb, on 3g up to 120mb, and 4g 150+mb.
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #9
Wow, those are pretty extreme numbers. Well, on 1G iPod Touches and 2G iPhones you'll have problems if the user has been surfing the web and stuff, but those devices are starting to fall off the market and can't use iOS 4 anyway. I am not entirely surprised to hear there is vastly more room on newer devices but I hadn't tested it that far.
Quote this message in a reply
Moderator
Posts: 771
Joined: 2003.04
Post: #10
Just for reference, on my iPhone 3G with iOS 4.1:
Free: 10.6 MB
Inactive: 13.1 MB
Active: 10.9 MB
Wired: 28 MB
Quote this message in a reply
Member
Posts: 54
Joined: 2010.10
Post: #11
Forgive the n00b question, but are these conversations about "normal" dram only or including texture/geometry space too?

I sure hope its the former!

Paul Johnson
Great Little War Game
Quote this message in a reply
Moderator
Posts: 704
Joined: 2002.04
Post: #12
@Applewood: I'm afraid it is the latter - iOS devices don't have separate RAM and VRAM... which hasn't stopped id/Carmack or Epic from putting together very pretty demos Wink

Mark Bishop
--
Student and freelance OS X & iOS developer
Quote this message in a reply
Member
Posts: 54
Joined: 2010.10
Post: #13
Hmmm, I'm kinda lost then tbh.

Our current game is being developed on PC with the iPad engine lagging behind but catching up fast. As such the game hasn't had any sort of optimisation/streamlining for iPad yet and weighs in at around 40Mb. Yet it runs without complaint (albeit a little on the slow side for now).
Oops. One day I'll stop seeing "iPad" when somebody writes "iPod". Sorry..

So, what's a sensible limit on iPad since I kinda derailed this thread already? :s

Paul Johnson
Great Little War Game
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #14
Personally, I don't think I'd worry about 40 MB on iPad. It's older iPhones/iPod Touches that are the real RAM wimps.

Well, and since you mentioned iPod, I'd probably still take a chance on it. If you make your requirement be iOS 4, then at least that cuts off first gen devices and encourages mainly owners of newer devices to buy your game.
Quote this message in a reply
Member
Posts: 54
Joined: 2010.10
Post: #15
Thanks. As you were... Smile

Paul Johnson
Great Little War Game
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  host_statistics memory usage output confusing kendric 0 3,970 Jan 11, 2010 02:50 AM
Last Post: kendric
  How much memory usage is too much? Gillissie 8 6,186 Oct 8, 2009 04:08 AM
Last Post: Madrayken
  Memory Usage haudio 9 4,656 Jan 29, 2009 01:22 AM
Last Post: haudio
  Guideline for Memory Usage aarku 7 4,899 Dec 27, 2008 07:19 AM
Last Post: jaguard
  How do you determine memory usage? green_ghost 5 4,518 Sep 8, 2008 09:01 PM
Last Post: green_ghost