Referencing an object after sending a release message to it
Referencing an object after sending a release message to it
- Subject: Referencing an object after sending a release message to it
- From: Jon Boone <email@hidden>
- Date: Sat, 06 Aug 2011 17:06:15 -0400
Folks,
I'm trying to make sure that I correctly understand the rules for manual memory management in Cocoa. In particular, I'm curious as to the safety of sending an object a release message and then using that object later on in the same method.
Here's the method that I'm curious about:
- (IBAction)createEmployee:(id)sender
{
// Create the new Person object
Person *p = [employeeController newObject];
// Add it to the content array of 'employeeController'
[employeeController addObject:p];
[p release];
// Re-sort in case the user has sorted a column
[employeeController rearrangeObjects];
// Get the sorted array
NSArray *a = [employeeController arrangedObjects];
// Find the object just added
NSUInteger row = [a indexOfObjectIdenticalTo:p];
NSLog(@"starting edit of %@ in row %ld", p, row);
}
Is it dangerous to send the release message to p right after adding it to the array? Should I put the release at the end of the method?
--jon
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden