Does removeObject release the object in an NSMutableArray of objects?

前端 未结 4 979
春和景丽
春和景丽 2021-02-16 00:29

I was wondering when you remove an object using removeObject in an array if that removed object is handled properly. Would the object being removed be released?

4条回答
  •  南笙
    南笙 (楼主)
    2021-02-16 00:34

    As everybody has said, the object of a NSMutableArray is released after it is removed from the array.

    If you don´t want to release the object, retain it just before you call remove object method. In this case, you are responsible for it to release it later:

    MyClass *objectToBeRemoved=[myArray objectAtIndex:indexPath.row];
    [objectToBeRemoved retain];
    [myArray removeObject:objectToBeRemoved];
    

提交回复
热议问题