Objective C Array and Object Release

后端 未结 3 781
不知归路
不知归路 2020-12-20 17:57

I have a newbie question regarding when to release the elements of a NSArray. See following pseudo code:

NSMutalbeArray *2DArray = [[NSMutableArray alloc] in         


        
3条回答
  •  眼角桃花
    2020-12-20 18:31

    No, you don't need to tell each object to be released. When you send a release method to an NSArray, it automatically sends a release method to each item inside first.

    So in your case, you send [2DArray release]. This automatically sends [array release] to every other array, which sends [obj release] to each object inside each array.

提交回复
热议问题