Received memory warning and app crashes
Solution 1
Well, to put it bluntly, you are just using too much memory. didReceiveMemoryWarning
gets called so that you can try free up some memory yourself so you dont crash the app (free up things that aren't in use that can be reloaded later).
The simulator isn't accurate hardware wise when it comes to running apps, so i wouldnt always rely on it, and thats probably why you dont get the warning on the simulator.
I cant really say what is causing your app to use so much memory from the information you have given
Solution 2
In ARC,the event(functionality) which create the received memory warning issue need to be inside @autoreleasepool{}
.Received memory warning issue might happens which overload from device memory.
Solution 3
Check app by instrument-->memory allocation
it will show all memory using by app and if there will any leak it will show.
Are you using heavy images?
Related videos on Youtube
Purva
Updated on June 25, 2022Comments
-
Purva almost 2 years
my app is crashing due to Received memory warning.
If i run the app for few minutes then on doing anything, the app crashes straightaway.
I have even checked for memory leaks but there are no memory leaks. Also the app is working fine in simulator.
What i have noticed is whenever i get a "Received memory warning", then "didReceiveMemoryWarning" method of every file in the project is called and then app crashes.
Any solution to this?
-
Daij-Djan about 11 yearsthis question WAY too broad.
-
iphonic about 11 yearsYou must be doing something flashy, case is not same on simulator and device, devices have lesser memory than the simulators.. If you can provide your snippet of code, it would be easier to answer..
-
Daij-Djan about 11 yearsA general hint: use instruments to find out what is using the memory
-
Matthias Bauch about 11 yearstemporarily comment out all code in
didReceiveMemoryWarning
. Maybe your app is not killed because it uses too much memory. Maybe your app kills itself because you do something wrong indidReceiveMemoryWarning
.
-
-
Purva about 11 yearsI am releasing all the objects in the dealloc and viewdidunload.
-
Fonix about 11 yearsyeah those wont help in this situation, because the view isnt unloading at this point, nor actually being dealloc'ed. this is for while the view is still alive, something is happening that is taking up too much memory, like loading a very large image or something. you will probably need to find a way to reduce your memory usage
-
Purva about 11 yearsI am initializing few arrays which are used again and again but when page reloads they are first released and then initialized again.
-
Fonix about 11 yearsare you sure they are not being held on to by some other object. going
someObject = nil
doesnt guarentee that it has been freed, since something else could be pointing to whateversomeObject
was pointing to, and therefor the reference count wouldnt have gone down to 0, and therefor not be deleted. can be tricky to spot and this situation wont show up as a memory leak either, because the memory in question is still valid because something is still pointing to it -
Purva about 11 yearsI have checked my app by instruments. There is no memory leak. Also live bytes are around 4-5mb on average and 12-13mb when app crashed. No, I am not using heavy images.