3

Can anyone help me? my app crashes on walkthrough, i had NSZombies disabled and i also had this code

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    [[NSURLCache sharedURLCache] removeAllCachedResponses];
}

but my app still crashes. The app contains images and some webviews that loads local images. Please instruct me how to optimize the app to avoid crashes.

Thanks in advance

user2641085
  • 101
  • 3
  • 8
  • ARC? or standard way for memory management? – Apurv Jul 03 '14 at 06:40
  • Please show full error log. You can take a screen shot – Tony Jul 03 '14 at 06:41
  • i can't upload any pictures here yet, so here's the link http://picpaste.com/pics/Screen_Shot_2014-07-03_at_2.56.41_PM-fHWSrmRu.1404370971.png – user2641085 Jul 03 '14 at 07:03
  • possible duplicate of [Is it possible to debug "Terminated due to memory error"?](http://stackoverflow.com/questions/19203790/is-it-possible-to-debug-terminated-due-to-memory-error) – Andrew Aug 21 '14 at 20:02

3 Answers3

3

The screenshot shows multiple errors:

  1. The app got killed by the system because you are allocating way too much memory.

    Using 261.4MB memory is way too much! You say that you are loading local images. Make sure those images are as small as possible (in pixel size) and only kept in memory as long as they are needed on the current view. There are many discussions here on how to do that. If you don't find a solution, post a new question with your code, details on how many images and their pixel size, if you are using ARC or not, and also what you tried to fix it. Use the Allocations Instruments tool from Xcode to find out where in your code you are allocating too much memory.

  2. The console log shows lots of autolayout constraint issues.

    These should also be fixed. Post a new question with more details of such an issue if you can't fix it. There are also many discussion about such issues here that should help. Use the search feature of this website!

Kerni
  • 15,241
  • 5
  • 36
  • 57
  • A note: `+[UIImage imageNamed:]` caches every image it gives you and doesn't clear on memory warning, so you can rack up a ton of memory if you have a lot of pictures, even if you only use one or a few at a time. – Kevin Jul 03 '14 at 14:12
  • I have resolved all the autolayout issues, there are no more warnings printed on the logs but still the app uses a lot of memory, I have images that are on 800 x 600 on size, should i still make a low res for those? or what are the recommended sizes so that the image won't be pixelated when viewed in ipad? – user2641085 Jul 04 '14 at 09:49
  • Please follow the response from point 1 in my answer. Unless you know what exactly is using memory that isn't deallocated nobody can give you a proper answer. In general: 800x600 size shouldn't be an issue, unless you have lots of images in memory at the same time. – Kerni Jul 04 '14 at 10:09
0

When ever your are done with any allocated objects, set them to nil explicitly to free up memory.

Even if you are using ARC, this will speed up the clean up.

0

I somehow found a way to amplify memory usage, i just need to execute removeAllCachedResponses for every viewDidLoad of ViewControllers because the didReceiveMemoryWarning was quite late or being delayed to clear cached responses when the memory warning is triggered, it may not look good on the code but it prevents to store and fill up memory and caches. I can't still call it a solution but it is somehow a efficient preventive method to avoid memory leak.

user2641085
  • 101
  • 3
  • 8
  • 1
    In normal cases, `removeAllCachedResponses` does not require to be called. Use Instruments to check the leaks. – Raptor Dec 23 '14 at 06:31