Skip to content

Commit

Permalink
Merge pull request #15 from UrbanCompass/master
Browse files Browse the repository at this point in the history
nil out tableView delegate on dealloc
  • Loading branch information
ninjinkun committed Apr 8, 2014
2 parents e1b9b93 + 9a3adbe commit 2758294
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions DemoApp/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ @interface ViewController ()

@implementation ViewController

- (void)dealloc
{
// If tableView is scrolling as this VC is being dealloc'd
// it continues to send messages (scrollViewDidScroll:) to its delegate.
// This is fine if the delegate will outlive tableView (e.g. this VC would.)
// However, if the delegate is an instance that may be dealloc'd
// before the tableView
// (i.e. _scrollProxy may be dealloc'd prior to tableView being dealloc'd)
// the tableView will send messages to its delegate,
// which is defined with an "assign" (i.e. unsafe_unretained) property.
// This is a msgSend to non-nil'ed, invalid memory leading to a crash.
// If or when UIScrollView's delegate is referred to with "weak" rather
// than "assign", this can and should be removed.
self.tableView.delegate = nil;
}

- (void)viewDidLoad
{
[super viewDidLoad];
Expand Down

0 comments on commit 2758294

Please sign in to comment.