• 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: GC, plain C structs, and when to use __strong
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GC, plain C structs, and when to use __strong


  • Subject: Re: GC, plain C structs, and when to use __strong
  • From: Quincey Morris <email@hidden>
  • Date: Tue, 21 Sep 2010 16:13:13 -0700

On Sep 21, 2010, at 15:37, Sean McBride wrote:

> If I have a plain C struct that contains some Obj-C object pointers like:
>
> struct {
>  int boring;
>  NSString* string;
> } MyStruct
>
> What must I do to be safe in GC?
>
> a) I know I must allocate my structs using NSAllocateCollectable and
> NSScannedOption.
> b) I'm pretty sure I don't need a '__strong' in my struct declaration.
> (doc say "__strong is implicitly part of any declaration of an Objective-
> C object reference type.")
> c) I'm pretty sure if I use a pointer to this struct as an ivar, I must
> tag it with __strong.

At risk of getting myself into trouble, I'd say correct, correct and correct.

> d) I'm not sure about passing pointers to this struct around.  Need I
> tag all parameters and return values as __strong too?  ex:
>
> void DoThing (__strong MyStruct* param) { ... }

At ditto risk, I'd say no to '__strong'. Variable 'param' is a stack variable is therefore a *root* reference, and as such the concept of strong or weak doesn't apply. (That is, AFAIK, applying '__strong' or '__weak' to a stack variable *never* has any effect on its behavior in any way.)_______________________________________________

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: GC, plain C structs, and when to use __strong
      • From: "Clark S. Cox III" <email@hidden>
  • Prev by Date: Re: Access object from another view
  • Next by Date: Need functionality of CAShapeLayer in 10.5
  • Previous by thread: Re: NSOperation and threadDictionary
  • Next by thread: Re: GC, plain C structs, and when to use __strong
  • Index(es):
    • Date
    • Thread