objective c - self.dictionary[blah] = object with block that uses self: creates a ref-count loop in ARC? -


i've got class using arc has member property that's mutable dictionary. set value key in dictionary. value object holding block references self object.

- (void)dosomethinglaterwithvar:(id)var forslot:(id)slot {     self.dothingslater[slot] = [dolaterthingie doafternsecs: 5 block:         ^(dolaterthingie *dlt) {             [self.log addobject:@"did thingie!!!"]         }     ]; } 

have created ref-count cycle? it's bit of contrived example, captures i'm doing. i've managed wrap brain simple case, not sure how deep these cycles can go.

you have create weak self prevent retain cycle.

- (void)dosomethinglaterwithvar:(id)var forslot:(id)slot {     __weak id weakself = self;     self.dothingslater[slot] = [dolaterthingie doafternsecs: 5 block:         ^(dolaterthingie *dlt) {             [weakself.log addobject:@"did thingie!!!"]         }     ]; } 

in block, if don't use weak self, self hold on block , block hold on self , neither deallocated.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -