SwiftKickMobile / SwiftMessages

A very flexible message bar for UIKit and SwiftUI.
MIT License
7.31k stars 744 forks source link

Retain cycle when using SwiftMessages.PresentationContext #274

Closed gregoripolak closed 5 years ago

gregoripolak commented 5 years ago

Hi guy's, So I've been using SwiftMessages, which is pretty awesome. But I notice a retain cycle in my app caused by SwiftMessages.PresentationContext, The reason is because both:

case viewController(_: UIViewController)
case view(_: UIView)

Hold a strong reference to the View Controller\View. I suggest turning the cases to:

case viewController(_: Weak<UIViewController>)
case view(_: Weak<UIView>)

I tried opening a Pull request, but I don't have push permissions to this repo, Let me know what you think.

wtmoose commented 5 years ago

Hi. I'm aware of the strong references in presentationContext. I haven't changed them to weak references because it is a breaking API change and doesn't generally cause retain cycles. What are you doing to get into a retain cycle?

gregoripolak commented 5 years ago

Nothing special, I have a View Model that creates the Config with a presentationContext.viewController(Strong reference), I present the message via the view controller, so the view controller holds the message, and the message holds the view controller. I'll probably Fork this project

wtmoose commented 5 years ago

Good luck