LoginSignup
1
1

More than 5 years have passed since last update.

Avoid cycle retain in ARC environment

Posted at

ARC無し

block 内からの参照は自動的に retain される。 __block 指定の変数は retain されない。

__block typeof(self) bself = self;
b = ^{
    bself.prop = YES;
    int foo = bself->ivar;
};

ARC有り

__block は効かないので注意。
また型の指定に typeof(self) も使えない。

__weak TypeA *wself = self;
b = ^{
    wself.prop = YES;
    int foo = wself->ivar;
};

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1