I have an Objective-C class which one of it’s variables is an C++ object (most of my code is C++, but I need some ObjC classes to integrate with iOS libraries). Does Objective-C++ guarantees that the C++ object will be correctly destroyed when the Objective-C object is destroyed?
Some example code:
class MyCppClass {
// ...
};
@interface MyObjCClass : NSObject {
MyCppClass myCppObject; // is it ok to do it?
}
// ...
@end
Yes. After the
-deallocmethod is called, a hidden.cxx_destructmethod is called. This method calls all the destructors of all instance variables that have a destructor.