What's the retain-release convention in this scenario
What's the retain-release convention in this scenario
- Subject: What's the retain-release convention in this scenario
- From: Sarat Kongara <email@hidden>
- Date: Sat, 2 Nov 2002 07:58:13 -0800 (PST)
Hi,
I am trying to follow (religiously) the retain-release conventions in Cocoa to help myself. I thought I got it all covered until one fine day I got a bug (Signal 11). Actually this is my first Cocoa app, I am planning on spending the whole of Sunday going over code of every method in all my classes.
I actually found the bug, thanks to the crash report logs that get generated in /Library/Logs/CrashReporter. It was tough to find this one because the app was crashing when I was doing some specific function but not always, I had to do it multiple times and it crashes randomly ofcourse always while doing the same operation.
Here is the code
- (IBAction)deleteItems:(id)sender {
// some code here
NSString *rowText = [selectedItem itemName];
NSString *parentName = [[selectedItem parent] itemName];
// some code here
[self deleteCategoryNamed:rowText inParentNamed:parentName];
// some code here
}
- (void)deleteCategoryNamed:(NSString *)cName inParentNamed:(NSString *)bName {
// code here
if([[entry name] isEqualToString:bName]) // sometimes crashing code
// code here
}
I think the reason is bName in deleteCategoryNamed:InParentNamed is not valid sometimes.
So I fixed this by changing deleteItems: to this.
- (IBAction)deleteItems:(id)sender {
// some code here
NSString *rowText = [[selectedItem itemName] retain];
NSString *parentName = [[[selectedItem parent] itemName] retain];
// some code here
[self deleteCategoryNamed:rowText inParentNamed:parentName];
// some code here
[rowText release];
[parentName release];
}
Should I
1. Also retain and release cName & bName in "deleteCategoryNamed: inParentNamed:"
2. Or its only enough to retain and release in "deleteCategoryNamed: inParentNamed:"
3. Can I expect the return value of a method call to be valid in the calling method.
All advice, feedback is really appreciated. Thanks.
Sarat Kongara
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.