Skip to content

Question about dealloc #82

Description

@gfxcc

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions