memory leak in "valueForKey"

Discussion in 'iPhone/iPad Programming' started by vashek, Dec 1, 2008.

  1. macrumors newbie

    Joined:
    Oct 2, 2008
    #1
    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

    Code:
    //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
     

Share This Page