• 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: Ugly bug in Foundation, beware!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Ugly bug in Foundation, beware!


  • Subject: Re: Ugly bug in Foundation, beware!
  • From: "Louis C. Sacha" <email@hidden>
  • Date: Thu, 3 Jun 2004 08:31:03 -0700

Hello...

Using google to search developer.apple.com (+"shallow copy" site:developer.apple.com) pulls up the following:

http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Concepts/HowToImplCopy.html

"The implementation of an instance variable's set method should reflect the kind of copying you need to use. You should deeply copy the instance variable if the corresponding set method copies the new value as in this method:"
...
"You should shallowly copy the instance variable if the corresponding set method retains the new value as in this method:"
...
"Similarly, you should shallowly copy the instance variable if its set method simply assigns the new value to the instance variable without copying or retaining it as in this method:"


In other words, since NSArray retains the objects that are added to it, copy should be implemented using a shallow copy. Since NSDictionary copies keys and retains objects added to it, when copy is used on an NSDictionary it falls in between a shallow and deep copy -- the dictionary's keys are copied again but the objects are not.

Also, when you really need to force a deep copy, you might want to consider using archiving to do it if you are dealing with objects that support the NSCoding protocol.

Hope that helps,

Louis


Other relevant links:

Regarding CoreFoundation
http://developer.apple.com/documentation/CoreFoundation/Conceptual/CFMemoryMgmt/Concepts/CopyFunctions.html
"In contrast to simple objects like CFString and CFData, the "CreateCopy" functions provided for compound objects such as CFArray and CFSet actually perform a shallow copy."
"The current release of Core Foundation does not include functions that perform deep copying."

More on implementing copy in Cocoa:
http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Tasks/ImplementCopy.html
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >Ugly bug in Foundation, beware! (From: Ondra Cada <email@hidden>)
 >Re: Ugly bug in Foundation, beware! (From: Zach Wily <email@hidden>)
 >Re: Ugly bug in Foundation, beware! (From: Ondra Cada <email@hidden>)

  • Prev by Date: Problems linking a standalone Java Cocoa app
  • Next by Date: Re: Feeding NSUnarchiver bad data can cause crash
  • Previous by thread: Re: Ugly bug in Foundation, beware!
  • Next by thread: Is that really a bug at all? (was: Re: Ugly bug in Foundation, beware!)
  • Index(es):
    • Date
    • Thread