Tag: 自动ref counting

消息__weak对象?

如果我发送消息给弱对象会发生什么? 发送消息是否拥有该对象并将其保存在内存中直到返回? 我正在考虑这种模式: __weak MyObject *weakSelf = self; dispatch_async(dispatch_get_main_queue(), ^{ [weakSelf doSomeAction]; }); 假设发送消息时weakSelf不为零,可能在doSomeAction正在工作时解除分配,还是保证在doSomeAction返回之前保持有效?

弱的对象在NSDictionary?

我想存储在NSDictionary的对象的归零弱引用。 这是为了参考一个父NSDictionary ,所以我可以爬行备份大型结构,而不search。 我不能在这里使用__weak ; 即使我的本地引用很弱, NSDictionary也会存储一个强引用,这个对象被弱引用。 而且,当然, NSDictionary不能nil对象。 我在iOS上,而不是Mac,所以NSHashTable不可用。 我只想要一个对象变弱。 其余的依然强大。 (我要发布我的答案,所以如果没有更好的答案,我有一些可以接受的东西,但我希望有人有更好的答案。)

ViewController从NavigationController中移除后,AVPlayer继续播放

所以我在我的项目中使用ARC,当我添加一个AVPlayerLayer它工作得很好,但是当我从我的UINavigationItempopupUIViewControllervideo继续在后台播放。 有谁知道你会如何处理这个? 这似乎很容易,我只是俯瞰。 这是我最初实例化的代码。 self.currentItem = [[AVPlayerItem alloc] initWithURL:url]; self.player = [[AVPlayer alloc]initWithPlayerItem:self.currentItem]; self.avPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:player]; self.avPlayerLayer.bounds = self.view.bounds; self.avPlayerLayer.frame = CGRectMake(0,55, 1024, 670); self.view.backgroundColor = [UIColor clearColor]; [self.view.layer addSublayer:avPlayerLayer]; 这也是我如何拥有定义的属性。 @property (strong) AVPlayer *player; @property (strong) AVPlayerLayer *avPlayerLayer; @property (strong) AVPlayerItem *currentItem; 也许这完全是错误的。 我不确定何时使用(强)vs(弱)。 任何情况下,提前谢谢你的帮助。

Auto-ARC转换后:将保留的对象分配给不安全的属性; 对象将在分配后被释放

我只是使用Xcode的自动重构将旧项目转换为ARC。 @property (nonatomic, retain) NSMutableArray *cards; 被replace为: @property (nonatomic) NSMutableArray *cards; 这是有道理的,因为我读到的是“强”是默认状态。 但是,下面这行代码给了我标题中的错误: self.cards = [[NSMutableArray alloc] initWithCapacity:54]; 这个错误是通过joinstrong回来解决的: @property (nonatomic, strong) NSMutableArray *cards; 但是,如果我需要返回并strong每个@property声明是retain …为什么ARC重构将它们全部删除?

ARC推出的新型限定符是什么?

自动引用计数(ARC)引入了一些新的types限定符。 我见过__strong和__weak ,但是他们做了什么?

如何禁用整个组/文件夹的ARC文件?

我知道你可以设置编译器标志-fno-objc-arc来禁用-fno-objc-arc中编译源文件中的每个文件的自动引用计数(ARC),但是我怎样才能做到这一点,而不必做每一个文件文件一次? 我问的原因是我已经添加了一个大的库到我的应用程序,我需要为超过100个文件设置-fno-objc-arc编译器标志。

用ARC手动保留

在ARC之前,我有以下代码,在asynchronous操作正在进行时保留委托: – (void)startAsyncWork { [_delegate retain]; // calls executeAsyncWork asynchronously } – (void)executeAsyncWork { // when finished, calls stopAsyncWork } – (void)stopAsyncWork { [_delegate release]; } ARC与这种模式有什么相同之处?

objective-c ARC只读属性和私有setter实现

在ARC之前,如果我想让一个属性只读来使用它,但是可以在课堂上书写,我可以这样做: // Public declaration @interface SomeClass : NSObject @property (nonatomic, retain, readonly) NSString *myProperty; @end // private interface declaration @interface SomeClass() – (void)setMyProperty:(NSString *)newValue; @end @implementation SomeClass – (void)setMyProperty:(NSString *)newValue { if (myProperty != newValue) { [myProperty release]; myProperty = [newValue retain]; } } – (void)doSomethingPrivate { [self setMyProperty:@"some value that only this class can […]

我如何知道我的程序是否启用了ARC?

我使用Xcode项目向导创build了一个支持ARC的项目。 与没有ARC支持的程序相比,我没有注意到任何差异。 有什么提示可以告诉我,如果我的程序支持ARC? 我正在使用XCode 4.2.1 Build 4D502

容器UIViewController不释放它的子视图控制器

我有一个自定义的容器UIViewController有六个子UIViewControllers和一组用户交互切换子视图控制器的选项卡。 问题是当我的容器视图控制器被释放子视图控制器不是。 我已经validation了子视图控制器不是通过向它们的dealloc方法添加一些debugging代码来释放的,只要它们的视图没有被添加到容器视图控制器的视图中,它们就被释放。 下面是我用来创build我的自定义容器视图控制器的代码摘录。 viewController指针是iVars。 我也使用ARC,所以这就是为什么没有实际的发布呼叫。 – (void)init { if ((self = [super init])) { vc1 = [[UIViewController alloc] init]; [self addChildViewController:vc1]; vc2 = [[UIViewController alloc] init]; [self addChildViewController:vc2]; vc3 = [[UIViewController alloc] init]; [self addChildViewController:vc3]; vc4 = [[UIViewController alloc] init]; [self addChildViewController:vc4]; vc5 = [[UIViewController alloc] init]; [self addChildViewController:vc5]; vc6 = [[UIViewController alloc] init]; […]