• 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: Simple NSView Question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Simple NSView Question


  • Subject: Re: Simple NSView Question
  • From: Andy Lee <email@hidden>
  • Date: Wed, 20 Aug 2008 13:50:37 -0400

On Aug 20, 2008, at 12:12 PM, Justin Giboney wrote:

- (void)addLabelWithText:(NSString *)text
{
NSTextField *newTextField = [[NSTextField alloc] initWithFrame:NSMakeRect(5,5,17,50)];
[newTextField setStringValue:text];
[self addSubview: newTextField];
//[self setNeedsDisplay:YES];
}

P.S. You're leaking memory here. Like all init methods, - initWithFrame: returns an object that you own, so you're responsible for releasing it. -addSubview retains newTextField, so this method should call [newTextField release] or [newTextField autorelease].


I know your problem is the view going away too early, not that it sticks around too long. But once you get that bug fixed you'll want to fix the memory leak -- especially if you're creating tons of subviews.

--Andy

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Simple NSView Question (From: Justin Giboney <email@hidden>)

  • Prev by Date: Re: Best Way to Handle Properties?
  • Next by Date: Re: passing an object between views
  • Previous by thread: Re: Simple NSView Question
  • Next by thread: Modifying TextEdit.app
  • Index(es):
    • Date
    • Thread