2010-10-25 136 views
0

我已經通過我的應用程序使用構建/分析,並能夠解決所有問題。爲什麼iphone-xcode泄漏工具顯示此代碼泄漏?

但下泄漏工具運行檢測到泄漏,並表示它來自TVC:viewDidLoad中,其中TVC是tableViewController

它進一步引用的NSArray - > sectionlist

它顯示一個malloc refct = 1 然後一個保留refct = 2 然後釋放refct = 1

這裏是viewDidLoad中下面接着的dealloc和報頭

我看不出這我有問題嗎?我錯過了什麼嗎?

比我在內,sectionList在其他2處僅引用其他代碼

-

  1. 在numberOfRowsInSection

    回報[自sectionList]計數]

  2. 中的cellForRowAtIndexPath

    [[細胞爲textLabel]的setText:[[自sectionList] objectAtIndex:indexPath.row]];

這是一個紅色的鯡魚?即;它是一個真正的泄漏還是泄漏工具只能夠顯示alloc,但隨後不顯示釋放發生在何時tvc被卸載的dealloc?

enter code here 

/// code 
//////////////////////// 

// property 
@synthesize sectionList = ivSectionList; 

/* 
********************************************* 
build list of sections 
********************************************* 
*/ 
- (void)viewDidLoad 
{ 
[super viewDidLoad]; 

// alloc a local array and init with values 
NSArray *sections = [[NSArray alloc] initWithObjects:@"A", @"B", @"C", nil]; 

// assign local array to tvc ivar 
[self setSectionList:sections]; 

// release local array 
[sections release], sections=nil; 
} 


/* 
********************************************* 
release ivSectionList 
********************************************* 
*/ 
- (void)dealloc 
{ 
[ivsectionList release], ivsectionList=nil; 
[super dealloc]; 
} 


//////// header 
//////////////////////////////////////// 
#import <UIKit/UIKit.h> 

@interface tvc : UITableViewController 
{ 
NSArray *ivsectionList; 
} 

@property (nonatomic, retain) NSArray *sectionList; 
@end 
//////////////////////////////////////// 

回答

1

泄漏(或儀器)告訴你在哪裏泄露的對象是創建

最有可能的是,客戶端不會釋放它。

一個子類也可能會濫用這個類,這是一個好主意,默認情況下使你的ivars @private

或者,您可能想要嘗試atomic讀取/寫入,以防萬一您遇到線程問題。

(但肯定的,摘錄看起來是正確的)

+0

使用活動監視器我看到一個添加內存,釋放模式作爲我的工作我的方式向上和向下的路徑,並從該TVC - 15.13 - 15.23 - 16.42 - 15.28 - 15.14可重複 - 似乎表明確實沒有泄漏。但是經過一系列的操作後我確實會炸燬,所以它可能會說出真相。將進一步調查並在稍後發佈結果。謝謝 – 2010-10-25 18:18:19

+0

這是一個合法的泄漏 - 花了一段時間,但我發現它。泄漏在別處 - 這個類的一個實例被創建並且沒有被釋放。崩潰是無關的。 – 2010-10-30 14:38:11

+0

很酷。感謝您的跟進。系統框架中偶爾存在泄漏,但這種情況不太常見。 – justin 2010-10-30 16:51:02