alibaba/BeeHive

CF指针的内存问题

Opened this issue · 2 comments

case '@': { // id
id ret = nil;
[inv getReturnValue:&ret];
return ret;
};

此处需getReturnValue:返回的是CF对象,需要把所有权转换到OC对象

            void *val;
            [inv getReturnValue:&val];
            id ret = (__bridge id)(val);
            return ret;

@humt0ng As apple's example code shows, it may be unnecessary.
https://developer.apple.com/documentation/foundation/nsinvocation/1437832-getreturnvalue?language=objc
When the return value is an object, pass a pointer to the variable (or memory) into which the object should be placed:

id anObject;
NSArray *anArray;
[invocation1 getReturnValue:&anObject];
[invocation2 getReturnValue:&anArray];

It just copy a pointer of the object, like how the NSError handling method does. Maybe the object has been retained before return to your context, just like how ARC handles the init method. So you don't need to do extra life cycle control operations. The best way to ensure this is to use instruments to inspect whether this lead to a memory leak or not.