0

I'm building an iOS 8 app, and I'm curious as to how much memory I am "allowed" to use up by the OS. I want to be well within the limits, currently, it hasn't gone above 50MB but sometimes it reaches like 42MB. How much can I expect to be usable? The app uses a lot of custom made functions and multiple for-statements with custom objects inheriting from NSObject.

Thanks! Erik

Erik
  • 2,500
  • 6
  • 28
  • 49
  • 2
    It varies strongly device to device – Ben Aubin Mar 15 '15 at 17:57
  • Device dependent, see this old question: https://stackoverflow.com/questions/6044147/memory-limit-and-ios-memory-allocation-in-iphone-sdk – uraimo Mar 15 '15 at 17:59
  • @penne12 the oldest device it can run on would be the iPhone 5(/C) and I guess it would have the least amount of memory capacity? – Erik Mar 15 '15 at 17:59
  • Just make sure that you're writing memory efficient code, lots of `break` statements in your `for` loops and using GCD when appropriate. Not retaining objects that are not needed. Lazy loading, instantiating e.t.c – Rob Sanders Mar 15 '15 at 17:59
  • I see, so while I'm using if-statements inside a for-loop, I can put a "break;" line after the if-statement matches to end the loop so that it won't need to try to compare irrelevant objects? Also, what's GCD? Haven't heard of it before – Erik Mar 15 '15 at 18:01
  • Exactly. `break` tells the program that you're done with the current loop so it stops looping and goes onto the next code, so yes `break` will probably be in `if` statements. (If you have multiple `for` loops you need a `break` for each loop.) GCD stands for Grand Central Dispatch and is to do with concurrent programming, and background threads. It is very useful for performance but needs understanding so you don't end up with more problems! Check [this](https://developer.apple.com/library/ios/documentation/General/Conceptual/ConcurrencyProgrammingGuide/Introduction/Introduction.html) out. – Rob Sanders Mar 15 '15 at 18:04
  • @RASS I'll definitely be looking up what you mentioned and add break; to my for-loops. I do think that the break; lines can have a pretty big impact as it has to allocate quite a few objects every time the for loop iterates and do multiple operations – Erik Mar 15 '15 at 18:14
  • @RASS I've taken memory precautions to the best of my knowledge so far but I can't make one of the ViewControllers go under 40MB, should I be concerned about that? – Erik Mar 15 '15 at 18:26
  • By the view controller being under 40MB do you mean this is the mem it takes up doing a specific task? I wouldn't be too worried as most iOS devices nowadays (esp if you're developing iOS 8+) have 1GHz+ processor and are pretty capable. Just make sure what you're doing is absolutely necessary and that you're making it as memory efficient as possible. What are you doing that takes up so much memory by the way? – Rob Sanders Mar 15 '15 at 20:42
  • @RASS I see, I'm trying to pinpoint the source of the memory usage but I'm not too skilled with instruments yet. Any ideas to pinpoint it? I have one method that get's repeated every 5 seconds but I tried to comment it out but doesn't look like that changed much – Erik Mar 15 '15 at 20:46
  • Xcode instruments are easy to use, and there are plenty of tutorials on the web but at that level of memory usage, I really wouldn't worry. It really depends on what you're doing but as an example a project I'm working on when it starts up, before you even start pressing buttons runs at 22MB. – Rob Sanders Mar 15 '15 at 20:51
  • @Erik, the oldest devices that run iOS 8 are the iPhone 4s and (I think) the iPad 2. I'm still running iOS 7 on my iPad 2 so I have an iOS 7 test iPad, so I'm not 100% positive about the iPad 2, but I have iOS 8 installed on my old 4s, so I AM positive on that one. – Duncan C Mar 15 '15 at 20:53
  • @RASS I'll look up some tutorials. The scenario is quite similar with my app, before the user starts interacting with the app in any way, the usage is around 30-40MB – Erik Mar 15 '15 at 21:34

0 Answers0