开发者

Iphone memory leak issue?

The memory is leaking in this code fragment, how to fix this memory leak ?

-(NSDictionary *)sanitizedFinancialLine:(NSDictionary *)theFinancialLine
{
 NSMutableDictionary *aFinancialLine = [NSMutableDictionary dictionaryWithDictionary:theFinancialLine];


for (id key in [aFinancialLine allKeys]) {
 id something = [aFinancialLine objectForKey:key];
 if ([something respondsToSelector:@selector(decimalValue)]) {
something = [NSDecimalNumber decimalNumberWithDecimal:[(NSNumber *)something decimalValue]]; // memory is leaking here
[aFinancialLine setObject:something forKey:key];
   }
}
 return [NSDic开发者_JAVA技巧tionary dictionaryWithDictionary:aFinancialLine];// and here
}


As written, there isn't a leak in that code.

What may be happening, though, is the NSDecimalNumber allocated on that line of code is being leaked because it is being over-retained (or under-released) somewhere else. Try build-and-analyze and/or turn on 'track retain events' in the allocations instrument.

Note that you could just return aFinancialLine without creating an NSDictionary instance (doesn't hurt to do so, though, and it is more defensive).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜