Question

I'm working with a C++ audio library in an iPhone app. Is there any Objective C / Cocoa memory management infrastructure I can use for my C++ objects, or do I need to just read up and learn C++ memory management?

Was it helpful?

Solution

You might find my latest blog post useful, at least the first half, as I discuss and compare both Objective-C memory management and idiomatic C++ memory management.

Executive summary is that most C++ devs use smart pointers.

With Objective-C++ there are additional things to worry about - in particular the fact that (at least by default), C++ value types held as members of Objective-C classes do not have constructors or destructors called automatically for you. You can call them explicitly, of course - but it's ugly. Personally I tend to just hold them by intrusive pointers (smart, reference counted, pointers where the ref count is held within the object itself - much like Obj-C pointers - which is why they are a good fit).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top