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

Question about dealloc #82

Open
gfxcc opened this issue Dec 28, 2015 · 0 comments
Open

Question about dealloc #82

gfxcc opened this issue Dec 28, 2015 · 0 comments

Comments

@gfxcc
Copy link

gfxcc commented Dec 28, 2015

why you implement dealloc like this?

  • (void)dealloc
    {
    [self.scrollView removeObserver:self forKeyPath:@"contentOffset"];
    [self.scrollView removeObserver:self forKeyPath:@"contentInset"];
    self.scrollView = nil;
    }
  • (void)willMoveToSuperview:(UIView *)newSuperview
    {
    [super willMoveToSuperview:newSuperview];
    if (!newSuperview) {
    [self.scrollView removeObserver:self forKeyPath:@"contentOffset"];
    [self.scrollView removeObserver:self forKeyPath:@"contentInset"];
    self.scrollView = nil;
    }
    }

why not just removeObserver in (void)willMoveToSuperview like this:

  • (void)willMoveToSuperview:(UIView *)newSuperview
    {
    [super willMoveToSuperview:newSuperview];
    [self.scrollView removeObserver:self forKeyPath:@"contentOffset"];
    [self.scrollView removeObserver:self forKeyPath:@"contentInset"];
    self.scrollView = nil;
    }

Another question,
when the function dealloc will be called?

Thanks

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

1 participant