I have MeetingUser C++ class; new_meetingUser is its object.
I want to add it to the NSMutableArray meetingUsersList, which I did using NSValue. However, I can't make out how to handle the memory of the object and the ownership of NSMutableArray.
MeetingUser *new_meetingUser = new MeetingUser(userName, dispName );
[meetingUsersList addObject:[NSValue valueWithPointer:new_meetingUser]];
You can add the C++ object to the array like that, but the array will not take ownership of the object. You will have to ensure that the object is not deleted while it's in the array, otherwise it will become a dangling pointer. Then you have to delete the object manually later, when you know it is safe to do so.
If you want the array to take ownership of the object, then you will have to use a CFMutableArray
. CFMutableArray
allows you to specify functions that called when objects are removed from the array, or when the array is deallocated. In your case, you want to set the CFMutableArray
to call delete
on the objects.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With