Release objects before returning a value based on those object?
Posted
by Moshe
on Stack Overflow
See other posts from Stack Overflow
or by Moshe
Published on 2010-04-01T03:26:32Z
Indexed on
2010/04/01
3:33 UTC
Read the original article
Hit count: 333
Consider the following method, where I build a string and return it. I would like to release the building blocks of the sting, but then the string is based on values that no longer exists. Now what?
Am I leaking memory and if so, how can I correct it?
- (NSString) getMiddahInEnglish:(int)day{
NSArray *middah = [[NSArray alloc] initWithObjects:@"Chesed", @"Gevurah", @"Tiferes", @"Netzach", @"Hod", @"Yesod", @"Malchus"];
NSString *firstPartOfMiddah = [NSString stringWithFormat: @"%@", [middah objectAtIndex: ((int)day% 7)-1]];
NSString *secondPartOfMiddah = [NSString stringWithFormat: @"%@", [middah objectAtIndex: ((int)day / 7)]];
NSString *middahStr = [NSString string@"%@ She'bi@%", firstPartOfMiddah, secondPartOfMiddah];
[middah release];
[firstPartOfMiddah release];
[secondPartOfMiddah release];
return middahStr;
}
© Stack Overflow or respective owner