0

I have the following class in my project, I am wondering if this implementation will end up doing retain cycle

public final class CalendarService: AccessTokenProvider {

  internal var accessToken: Observable<AccessToken> = ... 

  private let transport: CalendarTransport

  public init(factory: ServiceTransportFactory) {
    self.transport = factory.calendarServiceTransport()
  }

  func getCalendar() -> Observable<GCalendar, NSError> {
    return self.accessToken.prefix(maxLength: 1).flatMapLatest(self.transport.getCalendar)
  }
}

my question is the self in the flatMapLatest will create a retain cycle? also what if I do this too:

func getCalendar() -> Observable<GCalendar, NSError> {
  let methodRef = self.transport.getCalendar(token:)
  return self.accessToken.prefix(maxLength: 1).flatMapLatest(methodRef)
}
Bobj-C
  • 5,276
  • 9
  • 47
  • 83
  • 1
    Did you try to profile Leaks? That's the fastest way to check your implementation. – Sulthan Dec 10 '19 at 13:53
  • 1
    Finding Retain Cycle With Instruments: https://samwize.com/2016/05/30/finding-retain-cycle-with-instruments/ – Samps Dec 10 '19 at 14:12
  • Method references implicitly capture `self` (which is clearly necessary, because the method needs an instance to work with!) – Alexander Dec 10 '19 at 14:17

0 Answers0