我使用自定義的LocationDetail對象填充NSMutableArray * cityData。 cityData在viewDidLoad中創建並在dealloc中發佈。 某處的代碼,基於用戶行爲,我填充LocationDetail並將其添加到cityData陣列:NSString的內存管理問題
LocationDetail* d = [[LocationDetail alloc] init];
d.city = [NSString stringWithFormat:@"%S", (char*)sqlite3_column_text16(statement, 1)];
d.tz = [NSString stringWithFormat:@"%S", (char*)sqlite3_column_text16(statement, 3)];
d.country = [NSString stringWithFormat:@"%S", (char*)sqlite3_column_text16(statement, 2)];
d._id = [NSString stringWithFormat:@"%S", (char*)sqlite3_column_text16(statement, 0)];
[cityData addObject:d];
[d release];
當我與視圖控制器完成,並刪除它,泄漏公用事業說,我有一個泄漏的代碼在上面的[NSString stringWithFormat]全部4行的NSCFString中。
我試圖消除sqlite3的東西,並簡化調用像
d._id = [NSString stringWithFormat:@"%s", "a string"]
具有相同的結果。但是,如果我這樣替換NSString stringWithFormat:
d._id = @"a string";
泄漏消失。我不知道爲什麼如果我使用stringWithFormat會有泄漏,但如果我使用@「something」,則不會。有什麼顯而易見的,我做錯了嗎?
謝謝!
顯示如何爲`LocationDetail`定義每個`@ property`(`city`,`tz`,`country`和`_id`) – 2010-11-28 19:47:55
LocationDetail的屬性都是NSString *並定義他的方式:@property(非原子,保留)NSString * _id; – MirekE 2010-11-29 01:39:52