Reputation: 2439
I have the following piece of code. I am a bit unsure about retain/release concepts.
for (int i = 0; i < ABMultiValueGetCount(urls) ; i++) {
CFStringRef url = ABMultiValueCopyValueAtIndex(urls, i);
CFStringRef urlType = ABMultiValueCopyLabelAtIndex(urls, i);
urlString = (NSString *)url;
urlTypeString = (NSString *)urlType;
if ([urlTypeString hasPrefix:@"_"]) {
NSString * urlTypeSubString = [urlTypeString substringWithRange:NSMakeRange(4, ([urlTypeString length]-8))];
[mutableArray addObject:[NSString stringWithFormat:@"URL; %@: http://%@",urlTypeSubString,urlString]];
}else{
[mutableArray addObject:[NSString stringWithFormat:@"URL; %@: http://%@",urlTypeString,urlString]];
}
}
I have 2 questions.
Where should I release 'CFStringRef url' and 'CFStringRef urlType' in this code.
Should I release 'urlString' and 'urlTypeString', which are string types.
Upvotes: 1
Views: 718
Reputation: 4131
At the end of your for loop
for (int i = 0; i < ABMultiValueGetCount(urls) ; i++)
{
CFStringRef url = ABMultiValueCopyValueAtIndex(urls, i);
CFStringRef urlType = ABMultiValueCopyLabelAtIndex(urls, i);
urlString = (NSString *)url;
urlTypeString = (NSString *)urlType;
if ([urlTypeString hasPrefix:@"_"]) {
NSString * urlTypeSubString = [urlTypeString substringWithRange:NSMakeRange(4, ([urlTypeString length]-8))];
[mutableArray addObject:[NSString stringWithFormat:@"URL; %@: http://%@",urlTypeSubString,urlString]];
}
else
{
[mutableArray addObject:[NSString stringWithFormat:@"URL; %@: http://%@",urlTypeString,urlString]];
}
// Release here
CFRelease(url);
CFRelease(urlType);
}
Upvotes: 2
Reputation: 4649
At the end of the for...
And take a look at this : http://developer.apple.com/library/mac/#documentation/CoreFoundation/Conceptual/CFMemoryMgmt/CFMemoryMgmt.html
Upvotes: 3