你好,我有這個功能,從文件中獲取項目虛擬數據: 問題顯示在這些線路:潛在泄漏
NSString *path = [[NSBundle mainBundle] pathForResource: @"StatisticsDataJSON" ofType: @"TXT"];
- 對象的潛在泄漏。
NSMutableDictionary *statisticsResponse = [jsonParser objectWithString:data];
- 的潛在泄漏 - 存儲到 'statisticArray'
for (int i = 0; i < statsForDate.count; i++)
{物體的潛在的泄漏 - 存儲到 'jsonParser'
for (id key in statisticsResponse)
{物體的潛在的泄漏存儲爲's'的對象
if (self.statistics==nil)
{
self.statistics = [[NSMutableDictionary alloc]init];
NSString *path = [[NSBundle mainBundle] pathForResource: @"StatisticsDataJSON" ofType: @"TXT"];
NSError *error = nil;
NSString *data = [NSString stringWithContentsOfFile: path
encoding: NSUTF8StringEncoding
error: &error];
//NSLog(@"%@",data);
SBJsonParser *jsonParser = [[SBJsonParser alloc] init];
NSMutableDictionary *statisticsResponse = [jsonParser objectWithString:data];
for (id key in statisticsResponse) {
NSArray *statsForDate = [statisticsResponse objectForKey:key];
NSMutableArray *statisticArray = [[NSMutableArray alloc]init];
for (int i = 0; i < statsForDate.count; i++) {
Statistic *s = [[Statistic alloc]init];
s.locationId = [[statsForDate objectAtIndex:i] objectForKey:@"locationId"];
int value =[[[statsForDate objectAtIndex:i] objectForKey:@"visits"] integerValue];
s.visits = value;
value =[[[statsForDate objectAtIndex:i] objectForKey:@"totalUsers"] integerValue];
s.totalUsers = value;
value= [[[statsForDate objectAtIndex:i] objectForKey:@"uploads"] integerValue];
s.uploads = value;
value = [[[statsForDate objectAtIndex:i] objectForKey:@"downloads"] integerValue];
s.downloads = value;
value = [[[statsForDate objectAtIndex:i] objectForKey:@"apps"] integerValue];
s.apps = value;
[statisticArray addObject:s];
}
[self.statistics setObject:statisticArray forKey:key];
};
}
我發現在ststisticsResponse是自動釋放 - 解決問題:
NSMutableDictionary *statisticsResponse = [[jsonParser objectWithString:data]autorelease];
但後來東西SBJsonStreamParserAccumulator.m未能在dealoc功能。
什麼問題?
你不使用ARC嗎? – borrrden
舊項目 - 不是ARC – Cheese
我建議您更新它。從它的外觀來看,寫它的人不知道內存管理。無論是那個還是你都沒有展示全貌。所有你分配/ init你需要稍後發佈。你在做那個嗎? – borrrden