1

I have a strange bug in my app - while the app is running, I sometimes get a strange behavior where the application is "rebutting" and getting back to the first screen (as if ViewDidLoad was called again). There is no clear logic to it (sometimes it happens a few seconds after the app is running and sometimes I can lurk the bug for hours and it doesn't happen).

I suspect the problem relates to some memory issue - when I run the app with the debugger I can see in the LOG that I receive memory warning just before the bug occurs: Received memory warning. Level=1

  1. Is anyone familiar with this behavior? meaning, applications being "rebutted" when receiving memory warning?
  2. Since I have no idea what causes the memory issue, does anyone have any idea how should I track it? any recommended tools to do so?

Any help would be very much appreciated.

2
  • Use the leaks tool and the allocations tool to track memory issues. The first thing you can do is to build and analyse. This will point out all the places where you're leaking memory in the codebase. Jun 20, 2011 at 10:07
  • Memory warnings can easily come up without any leak, so they must be handled correctly anyway. In fact, they are just expected.
    – Eiko
    Jun 20, 2011 at 10:17

2 Answers 2

2

In case of a memory warning, some off-screen views might get released and later reloaded. If you don't handle this case properly (i.e. initializing fresh) the behavior you see is possible. The simulator can send your application a memory warning - so I suggest to play around with your app for a minute (different views, hierarchies, etc.), and then trigger the warning and see what happens.

2
  • Hi Eiko, thanks for the answer. I'm not sure I want to go there, but how do I "handle this case properly (i.e. initializing fresh)"? Do you mean I should implement "ApplicationReceivedMemoryWarning" or something like that and do an organized action in case it happens?
    – Ohad Regev
    Jun 20, 2011 at 10:29
  • There are callbacks, especially in the view controller classes. Although I wouldn't recommend it officially, implementing it to do nothing is often a good-enough solutions if you don't leak memory in your small-memory-footprint application. Getting it right needs to take more into account - I think there are some guides from Apple that go into detail.
    – Eiko
    Jun 20, 2011 at 10:50
1

Use the instrument tool to find leaks and object size at runtime. The memory warning also sometimes appear when we use UIImagePickerController to pick image. Also do a static analysis using clang static analyzer there is an gui app written by nikita zhuk find on google you will find the application. And last but not the least read some memory management guides.

UPDATE

Instrument is inbuilt into xcode. Run your project by selecting leaks from drop-down menu. Search on google about how to use instruments.

Here is an screenshot

enter image description here

For memory management search on google objective-c memory management you will get a bunch of articles. Also read objective-c 2.0 properties.

3
  • Thanks Rahul for the quick reply; few questions, if I may: 1. How do I get to the Instruments tool you had mentioned? 2. Do you have any recommandations for a memory management guide? one that is readable for someone who just got started
    – Ohad Regev
    Jun 20, 2011 at 10:23
  • Do you have any idea where the Instrument tool may be located in XCode4?
    – Ohad Regev
    Jun 20, 2011 at 11:03
  • @Ohad Regev here you go stackoverflow.com/questions/5304390/instruments-in-xcode-4
    – Rahul Vyas
    Jun 20, 2011 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.