2012-11-05 20 views
1

上午下面的代码并且使用ARC即使在ARC中,物体的潜在泄漏?使用

NSString *text; 
static NSString *[email protected]"Cell"; 
FeedsCell *cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) 
{ 
    cell = [[FeedsCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 
} 

if (indexPath.row == [feedsData count]-1) 
{ 
    [spinner startAnimating]; 
    [spinner setHidesWhenStopped:YES]; 

    OnDemand_fetch *getData = [[OnDemand_fetch alloc] init]; 

    if(nextUrl != NULL) 
    { 

     NSString *nextfbUrl = [getData getnextFbfeedUrl]; 
     NSString *nexturlEdited = [nextfbUrl stringByReplacingOccurrencesOfString:@"|" withString:@"%7C"]; 
     [demandfetch getFeedsInBackground:nexturlEdited]; 



    } 
    else 
    { 
     [spinner stopAnimating]; 
     self.myTableView.tableFooterView=nil; 
    } 

在分析,显示警告: “分配上线267和存储到‘的getData’的物体的潜在的泄漏”。

任何人都可以提出避免这种方法吗?这会造成什么麻烦?

感谢

+1

你确定它是ARC吗?这对我来说看起来很好。 'getData'在其他地方使用吗? – WDUK

+0

ya..am当然,我不使用其他地方的getData对象。 –

+0

更改OnDemand_fetch * getData = [[OnDemand_fetch alloc] init];'OnDemand_fetch * getData = [[[OnDemand_fetch alloc] init] autorelease];'。这是否会在建造时造成任何错误? – WDUK

回答

4

没错!但我正在使用ARC!为什么这种奇怪的可爱?

因为......你没有使用ARC。不知道你为什么这么认为。要转换为ARC,请转至编辑 - >重构 - >转换为Objective-C ARC。

How to convert to Objective-C ARC

如果你不想全力以赴,和ARC的一切,你可以作为一个编译器标志添加-fobjc-arc到要使用ARC文件,与项目是非ARC。

0

您只使用getData对象if(nextUrl != NULL)块内,你可以尝试将其移动到该块,并使其nil在最后,是这样的:

if(nextUrl != NULL) 
{ 
    OnDemand_fetch *getData = [[OnDemand_fetch alloc] init]; 
    NSString *nextfbUrl = [getData getnextFbfeedUrl]; 
    NSString *nexturlEdited = [nextfbUrl stringByReplacingOccurrencesOfString:@"|" withString:@"%7C"]; 
    [demandfetch getFeedsInBackground:nexturlEdited]; 
    getData = nil; 
} 
+0

,如果他真的使用ARC,则不需要这个。 ARC可以识别对象何时超出范围并释放它。 – yfrancis

+1

完全同意,我认为问题在于他没有在这个特定的文件中使用ARC – tkanzakic