• 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: Ken Thomases <email@hidden>
  • Date: Sat, 17 Apr 2010 08:49:33 -0500

On Apr 16, 2010, at 5:34 PM, Paul Sanders wrote:

> Another way might be to provide a method in each class or subclass called, say, zeroIVars and code it as (typed in mail):
>
> - (void) zeroIVars
> {
>    static ThisClass *clean_instance_of_this_class;
>
>    assert ([self isMemberOfClass: [ThisClass class]);
>    if (clean_instance_of_this_class == nil)
>        clean_instance_of_this_class = [[ThisClass alloc] init];
>    *self = *clean_instance_of_this_class;
> }

To be clear (for the archives), the above byte-wise copy of the object is only safe if the class has no pointers with ownership semantics among its instance variables.  See the discussion of object copying in the Memory Management Guide.

> This approach gives you the opportunity to end up with an object that is not just all zeroes (by way of the init method)

The init method has nothing to do with zeroing out instance variables.  Object allocation is responsible for that.

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

  • Follow-Ups:
    • Re: Zeroing out instance variables
      • From: "Paul Sanders" <email@hidden>
References: 
 >Zeroing out instance variables (From: Ben Haller <email@hidden>)
 >Re: Zeroing out instance variables (From: Ben Haller <email@hidden>)
 >Re: Zeroing out instance variables (From: "Paul Sanders" <email@hidden>)

  • Prev by Date: Re: Launch app with params as front process and wait?
  • 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