diff --git a/Sources/SegmentConsent/Blocker.swift b/Sources/SegmentConsent/Blocker.swift index f1444e6..5e80afa 100644 --- a/Sources/SegmentConsent/Blocker.swift +++ b/Sources/SegmentConsent/Blocker.swift @@ -14,7 +14,7 @@ public class ConsentBlocker: EventPlugin { internal let store: Store public var type: PluginType = .before - public var analytics: Segment.Analytics? + public weak var analytics: Segment.Analytics? public init(destinationKey: String, store: Store) { self.destinationKey = destinationKey diff --git a/Sources/SegmentConsent/Manager.swift b/Sources/SegmentConsent/Manager.swift index f3cbf12..edc8bd2 100644 --- a/Sources/SegmentConsent/Manager.swift +++ b/Sources/SegmentConsent/Manager.swift @@ -11,7 +11,7 @@ import Sovran public class ConsentManager: EventPlugin { public let type: PluginType = .before - public var analytics: Analytics? = nil + public weak var analytics: Analytics? = nil public let store = Store() internal var provider: ConsentCategoryProvider @@ -23,7 +23,10 @@ public class ConsentManager: EventPlugin { self.provider = provider self.consentChange = consentChanged - self.provider.setChangeCallback(notifyConsentChanged) + // call notifyConsentChanged from a closure to avoid retain cycles. + self.provider.setChangeCallback( { [weak self] in + self?.notifyConsentChanged() + }) } public func configure(analytics: Analytics) {