• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Question about block, ARC, self, and reference counting.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Question about block, ARC, self, and reference counting.


  • Subject: Question about block, ARC, self, and reference counting.
  • From: Scott Andrew <email@hidden>
  • Date: Thu, 12 Apr 2012 10:04:22 -0700

I have a question about retain cycles with ARC and blocks.

I have the following code:

    __weak MyViewController* controller = self;

    [UIView animateWithDuration:.25 animations:^{
        controller.alpha = 0;
    }
     completion:^(BOOL finsihed) {

       [controller showState];
     }];



-(void) showState {
	self.textView.text = self.stateText;
}

I have a question about what happens when I use self in showState. DId i just cause a reference counting issue where I now have an extra retain on self and it's not going to be cleaned up? The WWDC video say to use weak pointers to self in the block otherwise there could be retain cycle issues. This is an example. The utility functions are actually quite larger and called from multiple places. I'm not creating the strong refrence via a variable because these blocks won't be called if self doesn't exist.

Scott
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Question about block, ARC, self, and reference counting.
      • From: Ken Thomases <email@hidden>
  • Prev by Date: Re: Question about hebrew in textfields and textviews
  • Next by Date: Re: Question about block, ARC, self, and reference counting.
  • Previous by thread: Re: Networking and sleep
  • Next by thread: Re: Question about block, ARC, self, and reference counting.
  • Index(es):
    • Date
    • Thread