ios - RetainCycle with Globals -
let's in ios have:
in w2appdelegate.m:
globalviewcontroller *globalvc; - (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions { ... }
in someotherviewcontroller.m:
- (void)viewdidload { [super viewdidload]; [globalvc dosomething^{ [globalvc.somevariable dosomethingelse]; // there retain cycle here? }]; }
is there retain cycle here since have strong reference globalvc inside block.
globalvc -> block -> globalvc
is there retain cycle here since have strong reference globalvc inside block.
no. because blocks capture local variables only.
[globalvc dosomething^{ [globalvc.somevariable dosomethingelse]; // there retain cycle here? }];
globalvc
wasn't captured block because globalvc
global variable. no local variables here, block doesn't capture objects, block doesn't retain objects @ all.
Comments
Post a Comment