我有以下代码。我对保留/发布概念有点不确定。
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]];
}
}
我有两个问题。
我应该在哪里发布此代码中的'CFStringRef url'和'CFStringRef urlType'。
我应该发布'urlString'和'urlTypeString',它们是字符串类型。
答案 0 :(得分:3)
在for ...结束时
答案 1 :(得分:2)
在你的for循环结束时
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);
}