当前位置: 动力学知识库 > 问答 > 编程问答 >

objective c - ARC/ObjC++: ObjC objects as C++ member variable

问题描述:

ARC/ObjC++: ObjC objects as C++ member variable

Consider

class SomeCppClass {

NSLock * someLock ;

public:

SomeCppClass() {

someLock = [[NSLock alloc] init] ;

}

void atomicInsert(SomeOtherCppClass * c) {

[someLock lock] ;

// do atomic C++ stuff

[someLock unlock] ;

}

~SomeCppClass() {

// ? Huh ?

// ? can I just say:

someLock = 0 ;

// ?

}

}

Guess I had to encounter the opposite case of my previous question :-)

网友答案:

Under ARC, when the instance of SomeCppClass is destroyed, someLock will be released automatically. This will happen whether or not you define your own destructor.

You don't need to assign nil/null to that member in your destructor.

分享给朋友:
您可能感兴趣的文章:
随机阅读: