Reputation: 5078
I've declared a MutableArray rqst_entries in the header of my class as property and synthesized it too. In the viewdidload I added the following code:
self.rqst_entries = [NSMutableArray array];
Will it turn the this ivar to be autorelease and maybe release it earlier (before dealloc is called)
Thx for helping,
Stephane
Upvotes: 1
Views: 89
Reputation: 27354
[NSMutableArray array] returns an autoreleased object.
Everybody's answers are about the property rqst_entries
. Basically, you need a property that has a memory model of retain
. There are instances where you would want to use copy
, but this is usually for immutable types (NSArray, NSString, etc...). NSMutableArray is mutable (you can add entries, remove entries, and modify entries in the array).
You want to define your property like:
@property (nonatomic, retain) NSMutableArray *rqst_entries;
The part that really trips people up is doing an alloc / copy / retain in a property assignment like:
self.rqst_entries = [[NSMutableArray alloc] init];
because this will leak unless followed by a release
[self.rqst_entries release];
The best way to assign in this case is to use a local variable (at least if you need thread safety). like:
NSMutableArray *myArray = [[NSMutableArray alloc] init;
self.rqst_entries = myArray;
[myArray release];
I realize this is a VERY trivial example, but it does illustrate the point.
Upvotes: 1
Reputation: 9212
If you have defined your property to either retain
or copy
it will be held by the ivar and you will be fine. If you on the other hand have defined your property to be assigned
you will run into problems since [NSMutableArray array] is autoreleased.
Upvotes: 5
Reputation: 119242
If your property is retained, then you're fine. You've assigned an autoreleased object to your property, but this action has retained it for you.
Upvotes: 3