Let's say I've got c++ function combined with objective-c members.
The function gets std::string
and convert it to NSstring*
, and work with this variable before leaving...
Should i expect the NSstring*
to be released at the end of autoreleasepool
scope ?
void myclass::myfunc(context& ctx)
{
@autoreleasepool
{
std::string path = ctx.getData().path;
NSString *nsPath = [NSString stringWithUTF8String:path.c_str()];
... (do something with nsString, Should it be released after leaving the scope ?)
}
}
No you don't need to. According to the rule you only need release the variable if you are increasing its retain count in one of the following ways:
If you are getting a variable by any means but the above-mentioned ways, you don't own it, and hence you don't need to release it.
The string returned via [NSString stringWithUTF8String:path.c_str()]
is autoreleased string. It will be released once the current runloop finishes. So you don't need to release it.