[英]ARC warning - “Not safe to remove an unused autorelease”
I'm getting the following warnings and I haven't got a clue where to start, any ideas? 我收到以下警告,但不知道从哪里开始,有什么想法吗?
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'
The code came from here.... https://github.com/tylerneylon/moriarty/blob/c0d6daf65d86c22b8e5853aef00980f059c92fbc/NSObject%2BBe.m 代码来自这里.... 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
From the documentation: 从文档中:
NSObject+Be This category is designed to help with memory management. NSObject + Be此类别旨在帮助内存管理。 Specifically, this makes it easy to only work with autoreleased objects outside of a small number of ownership-allowed methods. 特别是,这使得仅使用少数允许所有权的方法之外的自动发布的对象变得容易。
So the posted code is to help with manual retain count memory management. 因此,发布的代码有助于手动保留计数内存管理。 Don't compile it with ARC, then. 那就不要用ARC编译它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.