views:

108

answers:

2

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?

A: 

Read up and learn C++ memory management.

stefanB
@morgancodes: Why don't you just remove the question if you're going to accept this *single* answer less than 10 minutes after asking it? I doubt anyone else will ever find this exchange interesting, enlightening or helpful.
Felixyz
…especially for such an obvious answer.
Abizern
In my defense, I though about a very elaborate answer explaining basics of c++ memory management compared to objective-c. However I realized it can be summarized as `learning c++ memory management` and the question was `do I need to learn c++ memory management` so I answered `yes`. I don't know a way of explaining how to manage c++ memory without calling it a `learning process`. In the end whatever you do to explain how to deal with c++ objects in objective-c, he will `learn how to manage c++ memory`. Hence my answer. Apologies if the answer is insultingly short, it was not my intent.
stefanB
It's a noob question and other noobs will probably find it useful. I wouldn't have asked it if I was able to find a duplicate question here. Perhaps I was a little quick accepting it, but it seemed it was a simple question with a simple answer.
morgancodes
stefanB: My comment wasn't directed at you, and I doubt Felixyz's was either. The point is the OP just accepted it as an answer within 10m without waiting to see if there was anything better. I have no problem with short answers.
Abizern
morgancodes: I have no issues with simple questions or answers. That is part of what this site is about. I just think you accepted a an obvious answer a bit too quickly, that's all.
Abizern
+2  A: 

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).

Phil Nash
Couldn't agree more with your post: "My point is that, because of smart pointers - made possible by deterministic destruction ... garbage collection is not really missed in C++."
stefanB