I am developing an application that needs to work on Linux, Windows and Mac OS X. To that purpose, I am using C++ with Qt.
For many reasons, on Mac OS X, I need to use CoreFoundation functions (such as CFBundleCopyBundleURL) that creates core objects that need to be released with CFRelease. But doing so generate a lots of these warnings:
*** __NSAutoreleaseNoPool(): Object 0x224f7e0 of class NSURL autoreleased with no pool in place - just leaking
All the code I’ve seen concerning these autorelease pools is written in Objective-C. Does anybody know how to create/use autorelease pools in C or C++?
idis a C declaration. You can simply add scope based autorelease pools to your cpp program like so:autorelease_pool.hpp
autorelease_pool.mm
In a cpp program:
An alternative (which can be very easy to use incorrectly) is to use the ObjC runtime directly – which would look like the following C program: