• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
primitiveValueForKey Memory Management
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: primitiveValueForKey Memory Management
      • From: Chris Hanson <email@hidden>
    • Re: primitiveValueForKey Memory Management
      • From: email@hidden
  • Prev by Date: Re: Accessing iTunes
  • Next by Date: Re: Wake from Sleep
  • Previous by thread: Re: Accessing iTunes
  • Next by thread: Re: primitiveValueForKey Memory Management
  • Index(es):
    • Date
    • Thread