Adding a C ++ Object to NSMutableArray

I have a MeetingUser C ++ class; new_meetingUser is its object.

I want to add it to the NSMutableArray collection list that I used with NSValue. However, I cannot figure out how to handle the object's memory and ownership of NSMutableArray.

MeetingUser *new_meetingUser = new MeetingUser(userName, dispName );
[meetingUsersList addObject:[NSValue valueWithPointer:new_meetingUser]];
+5
source share
3 answers

You can add a C ++ object to an array like this, but the array will not own the object. You will need to make sure that the object is not deleted while it is in the array, otherwise it will become a sagging pointer. Then you need to delete the object manually later when you know that it is safe.

, , CFMutableArray. CFMutableArray , , . CFMutableArray delete .

+4

, . ++ Objective-C - , , "". NSArray Objective-C. , , ++ - , Objective-C. Objective-C, ++ .

+1

- ObjC ++. , - , , ++ delete dealloc.

+1

All Articles