Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blockSelf over-retains self #9

Closed
hlung opened this issue Jul 20, 2012 · 1 comment
Closed

blockSelf over-retains self #9

hlung opened this issue Jul 20, 2012 · 1 comment

Comments

@hlung
Copy link

hlung commented Jul 20, 2012

In ATSDragToReorderTableViewController.m, self got retained when blockSelf is accessed in block, thus self is never deallocated (ARC).

- (void)viewDidLoad {
[super viewDidLoad];

if ( reorderingEnabled )
    [self establishGestures];


/*
 *  If app resigns active while we're dragging, safely complete the drag.
 */
__block ATSDragToReorderTableViewController *blockSelf = self; // self got retained when blockSelf is accessed in block, thus self is never deallocated (ARC)

resignActiveObserver = [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationWillResignActiveNotification object:nil queue:nil usingBlock:^(NSNotification *arg1) {
    if ( [blockSelf isDraggingCell] ) {
        CGPoint currentPoint = [blockSelf->dragGesture translationInView:blockSelf.tableView];
        [blockSelf fastCompleteGesturesWithTranslationPoint:currentPoint];
    }
}];
}
@hlung
Copy link
Author

hlung commented Jul 20, 2012

Solved. Use observer with selector instead of a block.

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(doResignActive) name:UIApplicationWillResignActiveNotification object:nil];

- (void)doResignActive {
if ( [self isDraggingCell] ) {
    CGPoint currentPoint = [self->dragGesture translationInView:self.tableView];
    [self fastCompleteGesturesWithTranslationPoint:currentPoint];
}
}

shusta pushed a commit that referenced this issue Aug 24, 2012
Merging in changes we made for Nice Mohawk's Ita. Full ARC support,
nothing but ARC. iOS 5+ only because of __weak. Tentative iOS 6 support.

Fixes an issue where ARC causes the NSNotification observer to over
retain self. #9

Uses iOS 5's new moving cell tableview methods rather than
delete/insert pairing.

Added separate LICENSE file. #10
@shusta shusta closed this as completed Aug 24, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants