Re: Simple NSView Question
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