Reputation: 2822
My iPhone application crashes due to low memory. I can see that a crashlog called lowmemory is saved after the crash. However, there are no leaks in the code.
Is there any other way to reduce the memory usage? I can see when profiling the app in simulator at one point the memory usage (allocations) reaches upto 91 mb and I suspect this is the point where the app is crashing on the device (iPhone 3GS). At that time I am doing a lot of string replacements (basically I am replacing around 100 tags in HTML).
Upvotes: 0
Views: 787
Reputation: 1317
You should try to use the Instruments tool. You can start the Instruments tool with XCode (cmd + I), and without XCode (cmd + space => Instruments).
If you start the Instruments with XCode, I suggest to use the "Leaks" option. You should press the "Leaks", select instead of "Statistics" the "Call Tree", and - in my experience is good to - check the following checkboxes: Hide Obj-C, Flatten recursion, Hide missing symbols, hide system libraries. Here the tool shows you the lines, which were appealed during the run.
Another way is to start the Instruments without XCode. You should use here the "Activity Monitor", select your device and record it's activity. You should double click on one of the statistics to get the statistics list. Find your app's name, and look at the "Real Memory" column. Play a little with your app, and if the memory is increasing and not deallocating, you should know which classes were used for the operation you done, and you should check your classes.
Note: If you start the Instruments without XCode, be sure, the app isn't started from XCode in debug mode. There was a bug in XCode 4.0 (I don't knew if later it was corrected or not), but it happened to me, that the Activity Monitor's Real Memory column had not shown the correct information.
Note2: if you are making memory management testings, you should do it always with a device. Always.
Edit: You can even try the "cmd + shift + B" shortcut key in XCode in your project, it suggests some possible memory leaks. It is useful sometimes, but the tool hasn't every time right :)
Upvotes: 0
Reputation: 589
First of all I don't think that your app uses up to 91mb (is too huge). I think 91mb - is the size of memory that was allocated (and can be deallocated but this number wasn't decreased). Could you check the Live Bytes column? About string replacements: I don't know how you use such functionality. But I advice you to avoid to use NSString in this case and use NSMutableString and change string values inside - this allows you to avoid every time allocation of NSString objects.
Upvotes: 3