4

I have been using XCode 3.2.4 when started developing iOS apps but now I turned to XCode 4.1 with iOS 4.3 SDK. I noticed that now dealloc method is not added automatically when I create UIViewController class from XCode template as were in XCode 3. Searching through Internet brings me that this might happen if I would created project with ARC (automatic reference count) but as I know this feature is implemented in XCode 4.2 only.

Should I add the dealloc method manually?

Lebyrt
  • 1,376
  • 1
  • 9
  • 18
Mitry
  • 375
  • 4
  • 13

2 Answers2

1

You can just go ahead and add dealloc. If ARC is indeed enabled, you'll get complains from the compiler.

Even when using ARC, dealloc is still sometimes needed if you need to do thing besides releasing objects (for example, un-resgister observers).

Joseph Lin
  • 3,324
  • 1
  • 29
  • 39
  • There are no complains from the compiler when I add the dealloc method. But I'm wondering, why automatic dealloc method disappeared. – Mitry Aug 15 '11 at 15:56
  • Then that sounds like a bug in Xcode. Maybe you'd like to file a report to Apple? – Joseph Lin Aug 15 '11 at 20:52
0

When not using ARC, yes... Use the dealloc method as usual.

If ARC is enabled, you should get warnings when explicitly using dealloc. Also check your project's build settings, for extra safety. You may use a project created with Xcode 4.2 in Xcode 4.1.

In such a case, the ARC setting will be located at the bottom, not at its usual place, as it's not supposed to be recognized by Xcode 4.1.

Macmade
  • 52,708
  • 13
  • 106
  • 123
  • you'll get warnings about `release`. `dealloc` is still allowed in certain occasions. – Joseph Lin Aug 15 '11 at 15:47
  • In dealloc, you'll usually need to call [ super dealloc ]. This will issue an error as well. – Macmade Aug 15 '11 at 15:49
  • In fact, I looked up my project's build settings and there is no information about XCode version. However, the situation I mentioned in my question, appears when I create project in XCode 4.1 from scratch. – Mitry Aug 15 '11 at 15:54
  • @macmade, you don't need to (in fact you shouldn't) add `[super dealloc]` in your `-(void)dealloc` method when using ARC. – Joseph Lin Aug 15 '11 at 20:57
  • 1
    Read the "ARC Enforces New Rules" section in "Programming With ARC Release Notes" for more detail. – Joseph Lin Aug 15 '11 at 20:59