Brian Tracy
Brian Tracy

Reputation: 6831

Is -didReceiveMemoryWarning useful anymore if I am using ARC?

When I create a new subclass of UIViewController in Xcode, it comes with default methods such as init and viewDidLoad. The last one though, is didReceiveMemoryWarning. This made me think, if I am using ARC, should I worry about this? Here is the default method.

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

The keyword here is dispose. Since I cannot explicitly call release on any objects while using ARC, should I even implement this method?

Upvotes: 2

Views: 1535

Answers (2)

user1459524
user1459524

Reputation: 3603

Yes, you should implement it, even if you simply leave it "as is". Just by calling [super didReceiveMemoryWarning] you allow your app to clean up memory in low memory conditions (which may be caused by something else than your app), such as release cached images (loaded via imageNamed or Storyboard, for example) or views that are not currently visible.

A good article: Managing Memory Level Warnings

Upvotes: 0

rmaddy
rmaddy

Reputation: 318924

Yes. Using ARC or MRC makes no difference. Either way your app could get memory warnings. Use the didReceiveMemoryWarning to clean up any memory that you can such as emptying caches or whatnot.

You can still cleanup objects under ARC so they are deallocated. You just need to remove all references to the object(s).

Upvotes: 6

Related Questions