Re: Custom Field Editor Problem
Re: Custom Field Editor Problem
- Subject: Re: Custom Field Editor Problem
- From: Ross Carter <email@hidden>
- Date: Tue, 02 Feb 2010 15:23:41 -0500
On Feb 2, 2010, at 2:02 PM, John Nairn wrote:
> I copied code from Cocoa documentation to create a custom field editor. It gets created OK and seems to work, but always crashes when the the window closes with the message
>
> Program received signal: “EXC_BAD_ACCESS”.
> sharedlibrary apply-load-rules all
>
> I created the custom editor in the window controller using code from Apple:
>
> - (id)windowWillReturnFieldEditor:(NSWindow *)sender toObject:(id)anObject
> {
> if([anObject isKindOfClass:[NSTextField class]])
> { if(!customEditor)
> { customEditor=[[BrowserFieldEditor alloc] init];
> [customEditor setFieldEditor:YES];
> }
> return customEditor;
> }
> return nil;
> }
>
> When the window controller is deallocated, it calls
>
> [customEditor dealloc];
>
> Finally, the entire custom editor, which is NSTextView subclass, is
>
> @implementation BrowserFieldEditor
>
> - (id)init
> { if(self=[super init])
> { NSLog(@"init field editor");
> }
> return self;
> }
>
> - (void)dealloc
> { NSLog(@"dealloc field editor");
> [super dealloc];
> }
>
> @end
>
> The "init field editor" message appears when created and the "dealloc field editor" appears just before the crash. If I change the window controller to not release the custom editor, the crash stops, but the "dealloc field editor" message never appears (i.e., a memory leak). Also the Apple documentation explicitly says:
>
> The custom field editor should be released in an appropriate place, such as the dealloc method of the window delegate object (if the field editor was never instantiated, therelease message has no effect and is harmless).
Well, the first thing I notice is [customEditor dealloc];. Do you mean release?_______________________________________________
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