0

I received two memory warnings. It doesn't show warning level. It shows brief phrase:

Received memory warning.
Received memory warning.

I received memory warning and after a few seconds my application crashed. Does my application crashed because I received memory warning?

I know that memory warning level 2 killes autorelease objects. Does memory warning without any level indication kill autorelease objects?

Voloda2
  • 12,359
  • 18
  • 80
  • 130

3 Answers3

2

Are you working with MRC? In that case, when memory warning is received, dealloc methos will be called to dealloc all the necessary views and objects to free some memory.

Check that everything is being released correctly in dealloc.

Autorelease objects are released automatically when your app goes out of their scope.

Antonio MG
  • 20,382
  • 3
  • 43
  • 62
1

autorelease objects aren't always released immediately

for example...if you have a loop where you alloc a lot of a autorelease objects the objects wont get released until the loop is over...so if they are big in size you can get memory warning and app crash before the loop is over and they have a chance to get released

if its this ..just alloc and release objects yourself to manage memory problem

skytz
  • 2,201
  • 2
  • 18
  • 23
  • in ARC we can't release own, so can we use nil instead of release? – Rajneesh071 May 20 '13 at 12:23
  • Well actually you can release objects yourself if you exclude file from ARC. And for the other objects in the class you can just call autorelease yourself( instead of being automatic) – skytz May 21 '13 at 15:29
  • but i want to use ARC, so how to free our object in ARC, – Rajneesh071 May 22 '13 at 05:03
  • add [[[object alloc]init]autorelease] when you init the object (if you don't use a method that returns an autoreleased object) or release the object yourself after you're done with it to avoid the problem above. To enable ARC for the full project...google it – skytz May 22 '13 at 16:13
0
  1. Use virtual memory iOS doesn’t use swap file but it does support virtual memory. If an app keeps a lot of data in memory for random access (like vocabulary in Letter Blocks 3D) you want to organize it as a mapfile rather then loading it to RAM with malloc() . An easiest way to do that is to call NSData initWithContentsOfMappedFile:

  2. Avoid stacking autoreleased objects When you instantiate objects like NSString with no explicit allocation they live until the release of your autorelease pool – typically until your app quits. Extensive usage of such techniques may lead to a lot of garbage in RAM. Use NSString initWithContentsOfFile: so you can later release it instead of NSString stringWithContentsOfFile: . The same rule applies to UIImage imageNamed: – this is not recommended to use for image loading.

  3. Handle memory warnings Unload unnecessary resources when handling memory warning. Even if you can’t unload any of your stuff call [super didReceiveMemoryWarning] in all your UIViewControllers. That will by default free some resources like UI controls on non-front views. Failing to handle this event may make iOS decide that your app deserves killing.

  4. Consider limited usage of animated view transitions Animations like flip transition are noticed to cause RAM usage spikes when executed. This feature is very neat and should be used in many cases but it may trigger memory warnings in a heavily loaded multitasking environment. In particular we strongly recommend to avoid animating OpenGL views.

  5. Test your memory footprint on device Use instruments to test. The most useful tools are Allocations, Leaks and Activity Monitor. Testing on simulator is not relevant in most cases since its memory footprint tends to be completely different. Once you test you can figure out how much RAM each part of your app uses, where are the bottlenecks and how you can optimize.

From: http://surgeworks.com/blog/lab-mobile/iphone/5-tips-to-reduce-memory-issues-in-ios-apps

LittleBobbyTables - Au Revoir
  • 32,008
  • 25
  • 109
  • 114
amit gupta
  • 1,167
  • 12
  • 29