Reputation: 2075
I use initWithNibName to load detail views. I was just thinking do these things need to be released at all? init is basically adding a retain count of 1?
Upvotes: 2
Views: 442
Reputation: 19469
@Mel:
Yes you need to release them.
A Part from Apple's Doumentation:
You own any object you create
You create an object using a method whose name begins with “alloc”, “new”, “copy”, or “mutableCopy” (for example, alloc, newObject, or mutableCopy).
But as such it has nothing to do with initWithNibName
but it is related to four words which allocate the memory that is 'mutableCopy','copy', 'retain' and 'alloc'. So hope it is clear to you now.
init
keyword just initializes an object. Allocation of memory is done though alloc
or retain
or copy
or mutableCopy
keyword
And the retain count of 1 that you are talking about is because of the alloc
keyword, not the initWithNibName
.
Hope this helps you.
Upvotes: 5
Reputation: 34185
Yes. Read this section. Anything starting with init...
gives you an object you own.
Upvotes: 5
Reputation: 1099
The section in question:
You own any object you create You create an object using a method whose name begins with “alloc”, “new”, “copy”, or “mutableCopy” (for example, alloc, newObject, or mutableCopy).
You can take ownership of an object using retain A received object is normally guaranteed to remain valid within the method it was received in, and that method may also safely return the object to its invoker. [...]
When you no longer need it, you must relinquish ownership of an object you own You relinquish ownership of an object by sending it a release message or an autorelease message. In Cocoa terminology, relinquishing ownership of an object is therefore typically referred to as “releasing” an object.
You must not relinquish ownership of an object you do not own This is just corollary of the previous policy rules, stated explicitly.
Generally, though, you should avoid thinking in terms of retain counts and focus on ownership. If you own it, it's up to you to release it.
Upvotes: 2