autorelease confusion

Discussion in 'iOS Programming' started by chhoda, Jun 26, 2012.

  1. chhoda macrumors 6502

    Oct 25, 2008
    hi all,

    i have an nsarray @propery(nonatomic, retain) in a class MyClass

    i do self.array = [MyAnotherclass getArray]; {static analyser points a memory leak here}

    in the getArray function of another class I allocate NSArray

    now the question is should i autorelease NSArray inside getArray function ?

    if yes, should I also do a release in dealloc of MyClass like [self.array release]; {confusion because, i am not allocating in MyClass ! }
  2. CodeBreaker macrumors 6502

    Nov 5, 2010
    Sea of Tranquility
    I assume this is a class method:
    [MyAnotherclass getArray] 
    If so, you should return an autoreleased array in getArray:

    As your property is of the retain type, you should also release it in dealloc. But be sure to check if it is NULL (in case it was never set), or better, instantiate it in init:

Share This Page