2012-11-05 64 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