I have a newbie question regarding when to release NSArray elements. See the following pseudo code:
NSMutalbeArray *2DArray = [[NSMutableArray alloc] initWithCapacity:10]; for (int i=0;i<10;i++) { NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:5]; for (int j=0;j<5;j++) { MyObject *obj = [[MyObject alloc] init]; [array addObject:obj]; [obj release]; } [2DArray addObject:array]; [array release]; }
My question here is when I release 2DArray, do I need to explicitly release each of its element (array) first? Also, before I let go of the array object, do I need to release each of its elements (MyObject) first?
I am new to Objective C. Please help. Thank you
memory-management arrays objective-c
david
source share