In my application i have enabled the ARC. But in my application following lines gives me memory leaks according to instruments. It is in ios 7.0.-(id)init{ variables = [[NSMutableArray alloc] init]; // Leak events = [[NSMutableArray alloc] init]; //Leak return self;}UpdateBut in my app if i do something like below it does not show me any leak. But i can't add items in to the variables.-(id)init{ variables = [[[NSMutableArray alloc] init] copy]; // No Leak events = [[[NSMutableArray alloc] init] copy]; //No Leak return self;}--NSString *utfString =[NSString stringWithUTF8String:(const char *)attr->children->content];//Leak---(NSObject*)createObjectForClass:(NSString*)className{ Class cls = NSClassFromString(className); NSObject *object = [[cls alloc]init]; //Leak if(cls != nil){ CFRelease((__bridge CFTypeRef)(cls)); } return object;}Does anyone has any idea how to fix this? 解决方案 My guess right now is that your entire object is leaking, which means that the NSMutableArrays created in -init also leak. The version that calls copy isn't leaking because the copy is probably returning a singleton instance of NSArray (as there are zero elements in it, and it's an immutable NSArray, there's probably a singleton instance for that). 这篇关于NSString stringWithUTF8String中的内存泄漏:启用了ARC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-11 08:08