• 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: Odd memory issue -- not a newbie
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Odd memory issue -- not a newbie


  • Subject: Re: Odd memory issue -- not a newbie
  • From: Dietrich Epp <email@hidden>
  • Date: Sun, 14 Dec 2003 00:28:03 -0800

On Dec 13, 2003, at 4:57 PM, Jonathan Jackel wrote:

I'm printing a text view in a special way, so I use a custom view.
Mainly, I'm interested in the text view's text storage, because that's
what I want to print. I tried to write my setter this way:

- (void)setMyStorage:(NSTextStorage *)newStorage
{
[newStorage retain];
[myStorage release];
myStorage = newStorage;
}

[snip]

Have you tried using:

- (void)setMyStorage:(NSTextStorage *)newStorage {
[myStorage release];
myStorage = [newStorage copy];
}

If the new storage object is immutable, then this is implemented as a -retain and you don't get any more overhead. If it is mutable, then you get a copy and you're okay if whatever is calling your function modifies it, such as if it's an object wrapping an internal buffer used for reading input.

In general, if you don't want a mutable object, always use -copy instead of -retain, and if you make a new immutable class, make -copy call -retain.
_______________________________________________
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.
  • Follow-Ups:
    • Re: Odd memory issue -- not a newbie
      • From: Jonathan Jackel <email@hidden>
References: 
 >Odd memory issue -- not a newbie (From: Jonathan Jackel <email@hidden>)

  • Prev by Date: Re: NSWindowController
  • Next by Date: Re: NSNumberFormatter in Panther
  • Previous by thread: Odd memory issue -- not a newbie
  • Next by thread: Re: Odd memory issue -- not a newbie
  • Index(es):
    • Date
    • Thread