griotspeak
griotspeak

Reputation: 13247

Should I dealloc @property items?

The basic rule that I have been going by is "if I alloc, I dealloc," but is this an overly simple view?

Upvotes: 4

Views: 600

Answers (2)

Dave DeLong
Dave DeLong

Reputation: 243156

The rule is "if you invoke a method that starts with new or alloc, is called retain, or contains copy, then you must (auto)release". (Easy way to remember this is the acronym: "NARC")

If you declare a @property as (retain) or (copy), then you are responsible for the backed object, and you must do:

[myProperty release];

in your dealloc method.

Upvotes: 13

Mustafa
Mustafa

Reputation: 996

Rule of the thumb: (Almost) never call dealloc directly, use release instead. There are some exceptions. For example, in your object's dealloc method you should call [super dealloc].

Upvotes: 1

Related Questions