• 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: Garbage collector vs variable lifetime
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Garbage collector vs variable lifetime


  • Subject: Re: Garbage collector vs variable lifetime
  • From: Andy Lee <email@hidden>
  • Date: Wed, 11 Jun 2008 08:42:19 -0400

On Jun 11, 2008, at 3:01 AM, John Engelhart wrote:
-(MyObject *)copyAndCombineWith:(MyObject *)object
{
 MyObject *copy = malloc(sizeof(MyObject));
 memcpy(copy, object, sizeof(MyObject));
 copy->answer += answer;
 copy->integerRING += integerRing;
 return(copy);
}

Do not use malloc() to instantiate objects. Do not use memcpy() to copy objects.


Despite looking like a C pointer, (MyObject *) is not a pointer to a struct; it is a reference to an object. Do not treat objects like structs.

The fact that sending a subclass of the declared base class behaves in a nearly indistinguishable manner is the result of careful manipulation and subtle bending of the rules, not because it's literally so.

No, it's a deliberate use of the rules. Or rather, you are making up rules that don't exist, and that you certainly didn't read in the docs.


Based on your misconceptions, I suspect you may also not understand method overriding, which is a crucial concept.

I suggest you review the docs on Objective-C, in particular:

<http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/chapter_9_section_1.html#//apple_ref/doc/uid/TP30001163-CH16-SW1 >
This chapter explains how static typing works and discusses some other features of Objective-C

Info on method overriding, in case you need it (I may be wrong about that), is here:


<http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/chapter_2_section_4.html#//apple_ref/doc/uid/TP30001163-CH11-BAJCDADF >

--Andy




--Andy

_______________________________________________

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: 
 >Garbage collector vs variable lifetime (From: Quincey Morris <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: Chris Hanson <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: John Engelhart <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: Chris Hanson <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: John Engelhart <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: Chris Hanson <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: John Engelhart <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: Chris Hanson <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: "Hamish Allan" <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: Chris Hanson <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: "Hamish Allan" <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: Charles Srstka <email@hidden>)
 >Re: Garbage collector vs variable lifetime (From: John Engelhart <email@hidden>)

  • Prev by Date: Link to zlib
  • Next by Date: Re: Link to zlib
  • Previous by thread: Re: Garbage collector vs variable lifetime
  • Next by thread: Re: Garbage collector vs variable lifetime
  • Index(es):
    • Date
    • Thread