primitiveValueForKey Memory Management
primitiveValueForKey Memory Management
- Subject: primitiveValueForKey Memory Management
- From: Phil Larson <email@hidden>
- Date: Sun, 29 May 2005 04:55:49 -0700
What is the reference count state of objects returned from
primitiveValueForKey?
I am trying to use CoreData without using bindings and have an
NSManagedObject subclass with the following method:
- (NSString *)name
{
NSString * tmpValue;
[self willAccessValueForKey: @"name"];
tmpValue = [self primitiveValueForKey: @"name"];
[self didAccessValueForKey: @"name"];
return tmpValue;
}
Inside my NSOutlineView datasource I have this:
- (id)outlineView:(NSOutlineView *)outlineView child:(int)index
ofItem:(id)item {
if (item == nil) {
return @"TopLevel";
} else if ([item isEqual:@"TopLevel"]) {
return [myObject name];
}
return nil;
}
- (id)outlineView:(NSOutlineView *)outlineView
objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
return item;
}
However, by the time the NSOutlineView calls the last method, it
seems the name string has become mangled or deallocated. The program
will quit with an EXC_BAD_ACCESS when I expand the arrow next to
"TopLevel".
It works properly if I change the:
return tmpValue;
to:
return [tmpValue copy];
or:
return [tmpValue retain];
I'm worried that this will result in a memory leak though.
What is the proper way to do this?
Sincerely,
Phil Larson
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden