0

I'm using a networker inside of a view controller. The networker has a weak delegate reference to the view controller. After a view controller is dismissed I kick off a timer to check whether the vc has been released. I noticed that it's not being released. I'm not passing my VC into my networker and the reference is weak. If I comment out setting the delegate it works fine.

    _networker = [[Networker alloc]
                  initWithSession:session
                  path:@"/path/"
                  parsingHandler:^id _Nonnull(NSDictionary * _Nonnull response) {
                      DataModel *const dataModel = (DataModel *)[DataModelParser parseDataModelFromResponse:response];
                      return dataModel;
                  }
                  hasLoadedOnce:NO];
    _networker.delegate = self;

and in my Networker class I have the following delegate:

@property (nonatomic, weak, nullable) id<NetworkerDelegate> delegate;

Shouldn't this prevent any retain cycle from being called? Is there some better way to debug this issue?

MichaelGofron
  • 1,310
  • 4
  • 15
  • 29
  • 2
    I’d suggest using the “Debug Memory Graph” button and confirm that it is indeed this that is keeping the strong reference. I don’t see any problem here, so I suspect the issue rests elsewhere. – Rob Mar 06 '19 at 00:10
  • Can you elaborate on what your timer-based check is doing? – Mattie Mar 06 '19 at 00:29
  • 1
    Repeating timers are a very common source of strong reference cycles. See https://stackoverflow.com/questions/30992338/how-to-debug-memory-leaks-when-leaks-instrument-does-not-show-them/30993476#30993476 for example of how to use “Debug Memory Graph” to find the source of the problem. – Rob Mar 06 '19 at 00:49
  • ah I figured out the issue thanks to rob's pointer. My networker is responsible for retrieving some data. This data is parsed into cells. One of these cells had a strong pointer back to my view controller resulting in a cycle so it wouldn't dealloc. I've since changed it to have a reference to a different object. – MichaelGofron Mar 06 '19 at 16:39

0 Answers0