BeeHive icon indicating copy to clipboard operation
BeeHive copied to clipboard

CF指针的内存问题

Open miyazaki2048 opened this issue 7 years ago • 2 comments

https://github.com/alibaba/BeeHive/blob/ff7aef5707481606c6d107cd00840728bb78075a/BeeHive/BHRouter.m#L71-L75

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

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

miyazaki2048 avatar Nov 15 '17 18:11 miyazaki2048

@ZoMinster

SoXeon avatar Nov 20 '17 05:11 SoXeon

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

MemoryReload avatar Jan 24 '18 16:01 MemoryReload