I have a Mac OS X App that I need to store objective-c objects in stl containers (as pointers). Everything works fine until I compile the program with garbage collection “supported” due to a custom framework that I need to use.
Problem is all the objects that get stored in the stl containers get released. Is there a way to tell the compiler to not collect those away and I’ll release them when I’m done with them?
Is this possible? Is there a way to have a framework that uses garbage collection and the main program doesn’t? That would also solve my problem. I can recompile the framework, but it heavily relies on GC.
You can disable garbage collection for individual objects using
NSGarbageCollector‘s disableCollectorForPointer: method. It will then hang around until you call-enableCollectorForPointer:on it.I believe (but I’m not totally sure) you can also use
CFRetain/CFReleaseonNSObjectsubclasses for more or less the same effect.