0

We have a construct like this (ARC code):

// load an object into an ivar using a block
self->objectLoader = [MyObject loadOnSuccess:^(MyObject *object) {

    // reference self from the block, so self is retained
    self->_object = object;

    // try to dereference the loader
    self->objectLoader = nil;        
}

The problem is that the object never deallocates, because self is never fully released. If I replace self with a weakSelf version, the object deallocates successfully.

Is there a way to nil the ivar so that the block it's "holding on to" is released and the object can be deallocated?

elijah
  • 2,904
  • 1
  • 17
  • 21
  • I don't see an obvious error in your code. Perhaps the error is in `MyObject`. - Did you try profiling with Instruments? The "Leaks" tool shows retain cycles very nicely. – Martin R Aug 15 '12 at 05:09
  • 1
    I typed up this long post, but in the end it was all speculation. You really need to do two things. First, include more code. Specifically, the entire code of both loadOnSuccess and this snippet... it's obvious there is more. Second, please rephrase your final question. I can only guess what you are asking, but it's very unclear what you are actually trying to achieve -- using a weak self is the usual way to break retain cycles... – Jody Hagins Aug 15 '12 at 05:16
  • thanks for the feedback, folks. I needed the validation that I wasn't insane. In the end: I was using an older version of A2DynamicDelegate that wasn't releasing correctly in some cases; I got the newest version in there and it was fixed. Thanks again! – elijah Aug 15 '12 at 19:28

0 Answers0