• 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: Overriding -copyWithZone: the right way
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Overriding -copyWithZone: the right way


  • Subject: Re: Overriding -copyWithZone: the right way
  • From: "M. Uli Kusterer" <email@hidden>
  • Date: Fri, 5 Nov 2004 19:31:36 +0100

At 17:46 Uhr +0100 05.11.2004, Michael Becker wrote:
- (id)copyWithZone:(NSZone *)zone {
PCShoppingCartCell *copy = [[ PCShoppingCartCell alloc] initImageCell:nil];
return copy;
}


This does not crash, but it looks so suspiciously memory-leaking... (the alloc/init is not paired with a release on my side). When trying to follow the (few) suggestions the docs give me, I tried this (but it did not work, the app crashed as soon as the TableView wanted to redraw):

That's just fine. It doesn't leak, because methods with "copy" in their name, by definition, return retained objects. So, whoever calls this method knows they're responsible for releasing the object they get.


I'm not sure though whether you shouldn't be calling [super copyWithZone: zone] instead of allocating a new object, and then just copy over those instance variables your subclass adds to the ones of the superclass.
--
Cheers,
M. Uli Kusterer
------------------------------------------------------------
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
References: 
 >Overriding -copyWithZone: the right way (From: Michael Becker <email@hidden>)

  • Prev by Date: Re: Getting a carbon's info string
  • Next by Date: Re: Overriding -copyWithZone: the right way
  • Previous by thread: Re: Overriding -copyWithZone: the right way
  • Next by thread: Re: Overriding -copyWithZone: the right way
  • Index(es):
    • Date
    • Thread