PDA

View Full Version : memory leak in "valueForKey"




vashek
Dec 1, 2008, 08:07 AM
Hi All,

In my app i have some key value pairs stored in a text file. Whenever I try to get values using "valueForKey" (NSDictionary's object method) I get memory leak in the instrument(of size 16bytes). Please have a look at the code snippet


//get dictionary object
NSDictionary *dictionary = [[NSDictionary alloc] initWithContentsOfFile: strSearchFilePath];

//get Previous search string
NSString * stringValue = [dictionary valueForKey: @"SEARCH_STRING"];
NSLog(@"before ...string Value count = %i", [stringValue retainCount]);
[txtSearchField setText: stringValue];
NSLog(@"after ...string Value count = %i", [stringValue retainCount]);

//get persisted type
_searchTypeIndex = [[dictionary objectForKey: @"SEARCH_TYPE"] intValue];

//release dictionary
[dictionary release];


Note: "txtSearchField" is of type UITextField control

following is the output of the debugger, strange retainCount value
before ...string Value count = 1
after ...string Value count = 3


the search file content
"SEARCH_STRING" = "new year";
"SEARCH_TYPE" = "2";


Keshav