sammcewan / WYPopoverController

WYPopoverController is for the presentation of content in popover on iPhone / iPad devices. Very customizable.
Other
253 stars 74 forks source link

Fix potential retain cycle with inView ivar #43

Closed tkach closed 9 years ago

tkach commented 9 years ago

Hi, @sammcewan Thanks a lot for supporting this component, it's really helpful and convenient in use.

But I found a possible memory issue that might appear in some cases.

For example, if popover controller should be presented from a view, retain cycle may occur:

MyView creates popover, holds strong reference to WYPopoverController, and calls -(void)presentPopoverInRect:rect inView:self ... method.

At this moment, WYPopoverController assigns strong reference of MYView to inView ivar. But this leads to retain cycle and MYView and WYPopoverController instances will never deallocated.

Adding __weak attribute to inView ivar can lead to crashes when popover is still presented but inView is already deallocated, So it seems that solution to breaking retain cycle is to assign inView = nil in -(void)dismissPopover method.

Thanks!

sammcewan commented 9 years ago

I've manually merged this due to big recent changes, thank you!

tkach commented 9 years ago

Thanks a lot :)