0

I have some code in a UIViewController that isn't being deallocated, which I don't know whether or not is causing the issue. I can't easily comment it out because it's used in a lot of places. Would this code create a strong reference cycle?

class something {
    var A = B()
    var C {
        get {
            return self.A.D
        }
    }
}

Does property C cause a retain cycle?

Dasun Cathir
  • 415
  • 1
  • 4
  • 9
  • 1
    Property C doesn't as it is a computed property. A retain cycle requires just that - A cycle, so if you said `mySomething.A.someProperty=mySomething` you could have a retain cycle – Paulw11 Jul 27 '15 at 02:16
  • No, this this computed property would not cause strong reference cycle. If you had a property which was the closure that had a strong reference to `self`, then you might have a strong reference cycle. But you do not have one here. – Rob Jul 27 '15 at 02:20
  • thanks. i was actually able to comment out my code and replace that in multiple files, and my problem is elsewhere anyway. – Dasun Cathir Jul 27 '15 at 02:21
  • If you run the Instruments "Allocation" tool with the "record reference counts" feature (now on by default), you can track down where this is being retained. See latter half of http://stackoverflow.com/a/14105056/1271826. Typical culprits include repeating timers, closures, or anything where you referenced `self` in some delegate object, etc. or sometimes people accidentally have circular references between their view controller segues. – Rob Jul 27 '15 at 02:26
  • hey, thanks for the help again. i'm running Instruments, and it appears that it *is* being deallocated. I have a recorded type for my class name, and it appears when I go to that view, and is removed from the Allocations table when the view controller is dismissed. But, I have a breakpoint in my deinit method, which is never hit (as well as a print statement that never shows up in the console). any ideas? – Dasun Cathir Jul 27 '15 at 02:33
  • hmm, ok, I guess I need to read more about the deinit method. I have the print statement in a superclass, and once i added deinit to the subclass, it's now being called in the superclass. problem solved... – Dasun Cathir Jul 27 '15 at 02:39

0 Answers0