Memory leaks caused by Framework CoreFoundation

I am developing an application for the iPhone that mainly uses the address book and database. After extracting about 3,000 contacts from the address book, I attach string tags to the contacts (5 for each). I save tags in a database.

For load testing purposes, I added 10,000 tags to the application. But during the load testing of my application, I noticed some memory leaks that were not related to the application code, but are a set of instruction sets. Furthermore, the "Tools" shown Foundation library as responsible for "leakage" (wide use NSString, NSDictionary, NSArraywhich relates to the structure Foundation). My application crashes after 10 to 15 minutes of use. A Crash report mentions that the application crashed due to low memory.

Memory profiling using CLANG shows zero leaks. How can I solve these memory leaks? Are these leaks the real culprit of the accident? Are there any other tools to check for memory leaks?

+5
source share
4 answers

I often find that my leaks say they are caused by the Core Foundation (or any other structure, for that matter), but really are my own. With the exception of the simulator, you rarely find excessive leakage within the framework.

If you open the details panel on the right in the Tools, you can find your application methods here. This will give you an indication of where it might appear in your code from. One leak can spring many other leaks, and you may have to find the culprit of the upper level to get rid of lower levels.

, Clang -, . , .

+4

clang . .

, . .

, , "", ( , ), /.

, : http://www.friday.com/bbum/2010/10/17/when-is-a-leak-not-a-leak-using -heapshot- -, /

+1

, , . , . "" , - , . , , : ?

, , , . , , - :

@property () NSString * myString;

...

self.myString = [[NSString alloc] initWithString: @ "foo" ];

alloc + init , self.myString = . , dealloc :

[ myString]; self.myString = nil;

, self.myString =, . , :

myString = [[NSString alloc] initWithString: @ "foo" ];// setter, , setter, , setter.

self.myString = [[[[NSString alloc] initWithString: @ "foo" ] autorelease];

autorelease alloc + init.

, , , , , :

self.myString = [NSString stringWithString: @ "foo" ];

, . , , .

, , , - , , .

+1

u-: 1. , ,

NSString *string = [dictionary valueForKey:[dictionary2 valueForKey:@"something"]]

:

NSString *key = [dictionary2 valueForKey:@"something"];  
NSString *string = [dictionary valueForKey:key];
key = nil;
  • , :

    NSArray * array = [NSArray array];

, , :

NSArray *array = [NSArray array];
.... some code where array is using;
array = nil;

- , . 3. , . , , , , , .

u, u ( ), .

-1

All Articles