• 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: Mike Abdullah <email@hidden>
  • Date: Mon, 23 Jul 2012 09:36:05 +0100

On 23 Jul 2012, at 09:00, Andreas Grosam <email@hidden> wrote:

> Suppose, I have C-arrays defined as follows:
>
> int count = [dictionary count];
> id __unsafe_unretained values[count];
> id __unsafe_unretained keys[count];
>
>
> I fill these arrays with:
>
> [dictionary getObjects:values andKeys:keys];
>
>
>
> 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];
> }
> NSDictionary *other = [NSDictionary dictionaryWithObjects:values forKeys:keys count:count];
>
>
>
> 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.
>
> Is there a way to extend the lifetime of the created objects, or is there a way to "re-declare" the arrays so that ARC can maintain the references - or is there any other simple "trick"?
>
>
> Thanks for suggestions!  ;)

I think all this begs the questions:

- Why do you want to get these objects stored in arrays rather than a dictionary?
- Why C arrays, rather than NSArray?


_______________________________________________

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: ARC Extending Lifetime of Objects
      • From: Andreas Grosam <email@hidden>
References: 
 >ARC Extending Lifetime of Objects (From: Andreas Grosam <email@hidden>)

  • Prev by Date: Profound UITableView rendering-performance problem, but only at certain positions? mostly resolved
  • Next by Date: Re: [NSSound isPlaying] fails to indicate sound termination in Lion
  • Previous by thread: ARC Extending Lifetime of Objects
  • Next by thread: Re: ARC Extending Lifetime of Objects
  • Index(es):
    • Date
    • Thread