• 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
Passing param by reference then using within block throws exception
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Passing param by reference then using within block throws exception


  • Subject: Passing param by reference then using within block throws exception
  • From: Steve Mills <email@hidden>
  • Date: Tue, 20 Sep 2016 21:06:35 +0000 (GMT)

I'm turning on ARC for a project (yay) and have run into a problem I can't wrap my head around. It always worked fine before ARC. When I turn zombies on, doing "memory history 0x610004279ac0" can't find it in the history. Here's the method and the call to it:

-(void) doStuff:(NSString**)fillMeIn
{
   [array enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL* stop) {
      if(obj.flag) {
         *stop = YES;
         *fillMeIn = @"wow";
      }
   }];
}

NSString*         getFilledIn;

[thing doStuff:&getFilledIn];

The call to doStuff: results in EXC_BAD_ACCESS, or "*** -[CFString retain]: message sent to deallocated instance 0x610004279ac0" if I turn zombies on.

I tried changing the param type to (NSString** _Nonnull), thinking it was confused about my knowing that the reference will never be nil, but it didn't help. Then I got to thinking about the reference being assigned inside the block and changed it to:

-(void) doStuff:(NSString** _Nonnull)fillMeIn
{
   __block NSString*         noFillMeIn;
   
   [array enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL* stop) {
      if(obj.flag) {
         *stop = YES;
         *noFillMeIn = @"wow";
      }
   }];
   
   *fillMeIn = noFillMeIn;
}

That seems to fix it. Is there a better way to deref and assign to the param from within the block?

Sent from iCloud's ridiculous UI, so, sorry about the formatting
_______________________________________________

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: Passing param by reference then using within block throws exception
      • From: "Gary L. Wade" <email@hidden>
    • Re: Passing param by reference then using within block throws exception
      • From: Jens Alfke <email@hidden>
    • Re: Passing param by reference then using within block throws exception
      • From: Doug Hill <email@hidden>
  • Prev by Date: Success with NSTableView weak delegates?
  • Next by Date: Re: Success with NSTableView weak delegates?
  • Previous by thread: Re: Success with NSTableView weak delegates?
  • Next by thread: Re: Passing param by reference then using within block throws exception
  • Index(es):
    • Date
    • Thread