views:

64

answers:

1

I am not sure about this:

// assume value is a NSDecimal type and exists
NSDecimalNumber *decNum = [[NSDecimalNumber alloc] initWithDecimal:value];
[encoder encodeObject:decNum forKey:@"someKey"];
[decNum release];

I'm wrapping the NSDecimal into an NSDecimalNumber object. I have to release it somewhere. But I am not sure... does the encoder retain that object, or will my -release to the object be a problem in some situations? I believe that the encoder actually just takes a "snapshot" of the naked data of that object and remembers it, but again, not sure. Maybe someone can help clear things up. Searched the docs for "release" and "retain", but they dont mention it in context.

+1  A: 

Because you did an explicit alloc you are responsible for also doing a release. The encoder can use the object during your function call, but if it wants to keep it beyond that it needs to either retain it or copy it, but your code doesn't need to know what precisely it's doing.

David Maymudes
Thanks. I wasn't sure if that encoder will retain it if it needs it, but you're right, it shouldn't be my problem... if it needs it for longer, it must retain it. But wouldn't hurt if they mention it in the manual ;)
HelloMoon