How to relase NSDictionary

Discussion in 'iOS Programming' started by diyora, Aug 14, 2008.

  1. diyora macrumors newbie

    Joined:
    Jul 21, 2008
    #1
    Hello all,
    I am coding in cocoa for iPhone simulator.
    I used..
    for(int i = 0 ; i < 5 ; i++)
    {
    [menuList addObject: [NSDictionary dictionaryWithObjectsAndKeys:
    @"sdf",kTitleKey,
    @"sfs",kExplainKey,
    @"dgd",kWebKey,
    @"sdfsf",kPublishDateKey,
    nil]];
    }

    Now when i run code then i get console warning:
    NSAutoreleaseNoPool(): Object 0x10979c0 of class NSCFDictionary autoreleased with no pool in place - just leaking..

    It create problem for me some time.

    Thank you..
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    dictionaryWithObjectsAndKeys: returns an autoreleased NSDictionary. At some point in the future (normally the end of this or the start of the next time throug the run loop) this will be released/dealloced for you. This happens by the magic of a NSAutoreleasePool. For autoreleasing to work you need to have a NSAutoreleasePool instance. Normally you have one created when the application starts. Looking in the main file for my iPhone projects one is automatically created there for me. Have you edited this to remove it? If so add it back.

    You can also create your own autorelease pool for performance reasons. For example if your method is going to create a lot of autoreleased objects you might want them to get cleaned up faster than the normal system would. To do this you use

    Code:
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    ... You code here ..
    [pool release];
    
    Hope that helps...
     
  3. diyora thread starter macrumors newbie

    Joined:
    Jul 21, 2008
    #3
    Hi,
    thanks for reply..
    I can't edit main file.NSAutoreleasePool is there.
    I also put NSAutoreleasepool out for loop as i mention previous post.

    But i create problem for me to create table..

    thank you...
     

Share This Page