• 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: Fixing a leak in an NSFormatter
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fixing a leak in an NSFormatter


  • Subject: Re: Fixing a leak in an NSFormatter
  • From: Stéphane Sudre <email@hidden>
  • Date: Wed, 7 Apr 2004 22:26:00 +0200

On mercredi, avril 7, 2004, at 09:46 PM, Darrin Cardani wrote:

I have a custom subclass of NSFormatter. Using ObjectAlloc, I've found that the formatter's -attributedStringForObjectValue:withDefaultAttributes: method is leaking memory. Here's what it does:

It's a bit surprising it's not crashing a bit later

- (NSAttributedString*)attributedStringForObjectValue:(id)anObject
withDefaultAttributes:(NSDictionary*)attributes
{
// Get the non-formatted string
NSString* regularString = [ self stringForObjectValue:anObject ];
NSAttributedString* retVal = NULL;

// Copy the passed in attributes
NSMutableDictionary* newAttribs = [ attributes mutableCopy ];

// Add our font to the attributes
[ newAttribs setObject:mFont forKey:NSFontAttributeName ];

// Create an attributed string from the non-formatted one,
//but add our attributes
retVal = [ [ NSAttributedString alloc ]
initWithString:regularString attributes:newAttribs ];

// Clean up
[ newAttribs release ];
[ regularString autorelease ];

Why do you want to release regularString? It's already autoreleased.

The ending code should be AFAIK:

[ newAttribs release ];

return [retVal autorelease];
}
_______________________________________________
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: Fixing a leak in an NSFormatter
      • From: Darrin Cardani <email@hidden>
References: 
 >Fixing a leak in an NSFormatter (From: Darrin Cardani <email@hidden>)

  • Prev by Date: "Automatic outlets"?
  • Next by Date: Finding an disabling particular calls in an application?
  • Previous by thread: Fixing a leak in an NSFormatter
  • Next by thread: Re: Fixing a leak in an NSFormatter
  • Index(es):
    • Date
    • Thread