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

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -