2012-10-01 1 views
0

다음 경고가 표시되며 어떤 아이디어를 시작할 지 단서가 없습니다. 문서에서ARC 경고 - "사용하지 않은 autorelease를 제거하는 것은 안전하지 않습니다."

코드는 여기에서 온
NSObject+Be.m:36:3: [rewriter] it is not safe to remove an unused 'autorelease' message; its receiver may be destroyed immediately 
NSObject+Be.m:35:40: [rewriter] NSInvocation's getReturnValue is not safe to be used with an object with ownership other than __unsafe_unretained 
NSObject+Be.m:36:4: ARC forbids explicit message send of 'autorelease' 

.... https://github.com/tylerneylon/moriarty/blob/c0d6daf65d86c22b8e5853aef00980f059c92fbc/NSObject%2BBe.m

#import "NSObject+Be.h" 

@interface BeProxy : NSProxy { 
    id target; 
} 

+ (BeProxy *)beProxyForClass:(Class)class; 

- (void)forwardInvocation:(NSInvocation *)anInvocation; 
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector; 

@end 

@implementation BeProxy 

+ (BeProxy *)beProxyForClass:(Class)class { 
    BeProxy *beProxy = [BeProxy alloc]; 
    beProxy->target = [class alloc]; 
    return beProxy; 
} 
// 

// We assume the method called is an init method. The return value 
// may be a new value for self. 
- (void)forwardInvocation:(NSInvocation *)anInvocation { 
    [anInvocation setTarget:target]; 
    [anInvocation invoke]; 
    id object; 
    [anInvocation getReturnValue:(void *)&object]; //HERE 
    [object autorelease];       //HERE 
    [self release]; 
} 

- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector { 
    return [target methodSignatureForSelector:aSelector]; 
} 

@end 

//  


@implementation NSObject (Be) 

+ (id)be { 
    return [BeProxy beProxyForClass:[self class]]; 
} 

+ (id)beInit { 
    return [[[self class] new] autorelease]; 
} 

- (id)beCopy { 
    return [[self copy] autorelease]; 
} 

@end 
+0

해당 프로젝트는 ARC 환경에서 사용하기위한 것이 아닙니다. – Till

답변

4

:

NSObject의 +가이 범주는 메모리 관리에 도움이 설계 될

. 특히, 소유권이 허용되는 소수의 메소드 밖에있는 객체 인 autoreleased 에서만 쉽게 작업 할 수 있습니다.

게시 된 코드는 수동 보유 계산 메모리 관리를 돕는 것입니다. 그렇다면 ARC로 컴파일하지 마십시오.

+0

이것이 왜 실패했는지 궁금해합니다. 예, "수동 보유 횟수"가 "자동 해제"가 아닌 전체 답변이 정확하게 자리를 차지하는 것처럼 보입니다. – Till

+0

@ "수동 보유 개수"또는 MRC는 Objective-C 하에서 비 ARC 메모리 관리를위한 확립 된 이름 인 것 같습니다. –

+0

@NikolaiRuhe Pre-ARC는 일반적으로 "MRR"또는 Manual Retain-Release로 작성됩니다. – pkamb

관련 문제