• 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
NSFont and memory management
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSFont and memory management


  • Subject: NSFont and memory management
  • From: Mike <email@hidden>
  • Date: Mon, 10 Feb 2003 23:23:09 -0500

I have a two basic questions about NSFont and memory management:

1. The following is a snippet from a font selector control (just a button and a text field). It works fine, but something worries me. I would never treat a "normal" object like this, but I don't know if I should ever retain or release NSFont objects. Considering that "font" is an NSFont * instance variable in a single shared object, will the following code to leak horribly, or will the font management system be smart enough to know what is going on:

-(void)changeFont: (id)sender
{
NSFont *newfont; // if this code is fine, i assume this variable is useless?
newfont = [sender convertFont: font];
font = newfont;
[fontfield setStringValue: [NSString stringWithFormat: @"%@, %d",
[font familyName], (int)[font pointSize]]];
NSLog( @"Font changed to %@.", [font description] );
}

2. This kind of related to the previous question on how NSFonts are memory managed. It seems like I'm doing the right thing, but I just want to make sure. The NSFont class supports the NSCoding protocol, which is wonderful, but I was wondering... is it safe to archive NSFont objects, ie what kind of information do they store? Font family and point size? Or something less portable? Am I correct in assuming I should retain fonts if I unarchive them from an NSData object? Example:

-(void)loadPrefs
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSData *tempdata;
tempdata = [defaults dataForKey: @"Font"];
if ( !tempdata ) {
font = [NSFont userFixedPitchFontOfSize: 0];
} else {
font = [NSUnarchiver unarchiveObjectWithData: tempdata];
[font retain];
}
}

Thanks in advance,
Mike
_______________________________________________
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.

  • Prev by Date: Converting four char code
  • Next by Date: Re: Converting four char code
  • Previous by thread: Re: Converting four char code
  • Next by thread: Finding an application ?
  • Index(es):
    • Date
    • Thread