• 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
Re: ARC Extending Lifetime of Objects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ARC Extending Lifetime of Objects


  • Subject: Re: ARC Extending Lifetime of Objects
  • From: Ken Thomases <email@hidden>
  • Date: Mon, 23 Jul 2012 10:32:00 -0500

On Jul 23, 2012, at 3:00 AM, Andreas Grosam wrote:

> int count = [dictionary count];
> id __unsafe_unretained values[count];
> id __unsafe_unretained keys[count];

> Now, I would like to "reuse" these arrays through holding objects maintained by ARC (if possible):
>
> for (int i = 0; i < count; ++i) {
>    keys[i] = [keys[i] copy];
>    values[i] = [values[i]] copy];
> }

> This won't work in ARC, since the arrays are declared __unsafe_unretained and this would cause the newly created object immediately be deallocated once it is assigned to the array's element.
>
> What I would like to avoid is to use separate arrays (appropriately declared), and also avoid to disable ARC and maintain the release counts manually.

So you're aware of the simple and obvious solutions, but you have arbitrarily excluded them from consideration for no particular reason?  Why not just use a second pair of arrays?

There's no trick you can use, I don't think.  The lifetime qualifiers define the semantics of the variables.  Even if you could temporarily override them, that would lead the compiler to do the wrong thing at other places.  It would over- or under-release things.

Regards,
Ken


_______________________________________________

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

References: 
 >ARC Extending Lifetime of Objects (From: Andreas Grosam <email@hidden>)

  • Prev by Date: Re: Profound UITableView rendering-performance problem, but only at certain positions? mostly resolved
  • Next by Date: Re: NSDocument -canCloseDocumentWithDelegate::: not called when terminating
  • Previous by thread: Re: ARC Extending Lifetime of Objects
  • Next by thread: Re: ARC Extending Lifetime of Objects
  • Index(es):
    • Date
    • Thread