• 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: Zeroing out instance variables
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Zeroing out instance variables


  • Subject: Re: Zeroing out instance variables
  • From: "Paul Sanders" <email@hidden>
  • Date: Sat, 17 Apr 2010 15:37:15 +0100

> My understanding, which is vague and for which I have no references, is that it's handled in a manner similar to
> what was recently exposed via the associated references API (i.e. objc_setAssociatedObject and friends).
>
> That is, retain counts are stored outside of the instance.

In that case there is a danger that a pointer to whatever is referenced would be transferred to the copy of the object, which is not what you want.  One could test it like this:

    NSObject *a = [[NSObject alloc] init];
    printf ("%d\n", [a retainCount]);    // 1
    NSObject *b = [[[NSObject alloc] init] retain];
    printf ("%d\n", [b retainCount]);    // 2
    *b = *a;
    printf ("%d\n", [b retainCount]);    // 1
    [b retain];
    printf ("%d\n", [b retainCount]);    // 2
    printf ("%d\n", [a retainCount]);    // ?

If the last printf prints 2, my scheme doesn't work as a and b must now be referring to the same object at the Core Foundation object level.  I am, of course, far too lazy to test this or read up on it.

> Would be an interesting subject for Mr. Bumgarner to expound upon on his blog.

Yes it would.  We're lucky it's Saturday or he would probably have already poured cold water on the whole idea :).

Paul Sanders.
_______________________________________________

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: Zeroing out instance variables
      • From: Ken Thomases <email@hidden>
References: 
 >Zeroing out instance variables (From: Ben Haller <email@hidden>)
 >Re: Zeroing out instance variables (From: Graham Cox <email@hidden>)
 >Re: Zeroing out instance variables (From: Ben Haller <email@hidden>)
 >Re: Zeroing out instance variables (From: "Paul Sanders" <email@hidden>)
 >Re: Zeroing out instance variables (From: Ben Haller <email@hidden>)
 >Re: Zeroing out instance variables (From: "Paul Sanders" <email@hidden>)
 >Re: Zeroing out instance variables (From: Ken Thomases <email@hidden>)

  • Prev by Date: Re: Zeroing out instance variables
  • Next by Date: Re: Zeroing out instance variables
  • Previous by thread: Re: Zeroing out instance variables
  • Next by thread: Re: Zeroing out instance variables
  • Index(es):
    • Date
    • Thread