views:

78

answers:

2

I have a method which runs this:

Track* track = [[Track alloc] init:[obj objectForKey:@"PersistentID"] :[obj objectForKey:@"Name"] :[obj objectForKey:@"Artist"] :(NSInteger*)[obj objectForKey:@"Total Time"] :(NSInteger*)[obj objectForKey:@"Play Count"]];

[self setCurrentTrack:(Track*) track]; [track release];

Do I have to release track?

A: 

well, you don't HAVE to, but if you don't have to use it anymore then you should. also it's not necessary to have ":(Track*) track];" I personally prefer

[self setCurrentTrack:track];

because it's a more common practice.

Matt S.
Why is it a bug to have the typecast? It's not necessary, but it's not an error, either.
Carl Norum
well it's more common to have what I show above
Matt S.
+2  A: 

Yes. You are responsible for release'ing an object anytime you own the object. You own an object any time you send it an alloc, new, copy or retain message. Your currentTrack property should retain the track.

Jason Coco