关于C#:当ARC工作时?

When ARC working? Compilation or runtime?

本问题已经有最佳答案,请猛点这里访问。

当ARC(自动参考计数)工作时,目标C还是SWIFT?在编译阶段还是在运行时阶段?为什么重要?


编译器在编译时插入必要的retain/release调用,但这些调用和其他代码一样在运行时执行。


从苹果过渡到ARC发行说明

ARC is a compiler feature that provides automatic memory management of Objective-C objects.

Instead of you having to remember when to use retain, release, and autorelease, ARC evaluates the lifetime requirements of your objects and automatically inserts appropriate memory management calls for you at compile time. The compiler also generates appropriate dealloc methods for you.

启用弧的类示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@interface Person : NSObject
@property NSString *firstName;
@property NSString *lastName;
@end

@implementation Person

// ARC insert dealloc method & associated memory
// management calls at compile time.
- (void)dealloc
{
    [super dealloc];
    [_firstName release];
    [_lastName release];
}

@end