Git Product home page Git Product logo

Comments (1)

lyandy avatar lyandy commented on July 3, 2024

使用performSelectorWithArgs获取返回的对象,会直接释放
在getReturnFromInv:withSig:方法里
case '@': { // id
id ret = nil;
[inv getReturnValue:&ret];
return ret;
};
如果在id前面加上__autoreleasing就没有问题了,但是不知道具体原因是什么

原因是在arc模式下,getReturnValue:仅仅是从invocation的返回值拷贝到指定的内存地址,如果返回值是一个NSObject对象的话,是没有处理起内存管理的。而我们在定义returnValue时使用的是__strong类型的指针对象,arc就会假设该内存块已被retain(实际没有),当returnValue出了定义域释放时,导致该crash。假如在定义之前有赋值的话,还会造成内存泄露的问题。

NSObject *returnValue = nil;
// 有返回值类型,才去获得返回值
if (signature.methodReturnLength != 0)
{
void *tempReturnValue;
[invocation getReturnValue:&tempReturnValue];
returnValue = (__bridge NSObject *)tempReturnValue;
}
response(returnValue, nil);

from yycategories.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.