how to clean up a failed init without autorelease

Discussion in 'Mac Programming' started by blueillusion, Aug 18, 2008.

  1. blueillusion macrumors member

    Joined:
    Aug 18, 2008
    #1
    I have some sort of problem.

    Im making a bitmap library, and all works pretty well at the moment.
    however, i have one problem when i initialize the class with an invalid bitmap.

    I have a method called initWithContentsOfBitmap: (NSString *)path;

    This method does:
    self = [super init];
    After that, it goes on to allocate some composite objects, and then calls loadBitmapFromFile: (NSString *)path;, where path is supplied from initWithContentsOfBitmap.

    What i want, is when the path is invalid, i want the object to destroy itself before returning nil. Once the path is invalid, i can get initWithContentsOfBitmap to destroy all the objects it created, but im not sure out to get it to destroy itself without giving it the autorelease command.

    Any ideas?
     
  2. kpua macrumors 6502

    Joined:
    Jul 25, 2006
    #2
    If you return nil right away, it is safe to call [self release] from within -init. That's why we typically check for [super init] != nil.
     

Share This Page