samvermette/SVPullToRefresh — pull request #27 by chapados (2012-06-19 03:19:37+00:00)
Title: Only observe scrollview while pullToRefreshView is a subview.

KVO for scrollview properties was previously started in -init and removed in -dealloc.
However, the timing of dealloc is not determinant, since it may be called on another
thread. In cases where both the pullToRefresh and infiniteScrollingView are
present, it is possible to reach a condition where the scrollview (e.g. tableview)
is deallocated before KVO properties are removed. Since the
pullToRefresh views are stored in associated objects on the scrollview, it is also
not clear exactly when the associated objects will be released.
By implementing -[UIView willMoveToSuperview:] and managing KVO properties there, we ensure
that KVO is directly coupled to state of the scrollview's hierarchy. Note that we
still include a call to -stopObservingScrollview in -dealloc. This guards against
cases where UIView notifications may not be sent and is otherwise a no-op.