Re: NSDocument subclass not dealloced after promising data - best way out this?
Re: NSDocument subclass not dealloced after promising data - best way out this?
- Subject: Re: NSDocument subclass not dealloced after promising data - best way out this?
- From: Keith Blount <email@hidden>
- Date: Mon, 6 Dec 2004 08:55:49 -0800 (PST)
- Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
Many thanks for the reply. The way I have overcome
this currently is to provide some blank data when the
document closes, like this:
- (void)close
{
// Post some dummy data to the dragging pasteboard to
ensure that the NSDocument is deallocated...
NSAttributedString *attrStr = [[NSAttributedString
alloc] initWithString:@""];
NSData *RTFDdata = [attrStr
RTFDFromRange:NSMakeRange(0,[attrStr length])
documentAttributes:nil];
NSData *RTFdata = [attrStr
RTFFromRange:NSMakeRange(0,[attrStr length])
documentAttributes:nil];
NSPasteboard *pb = [NSPasteboard
pasteboardWithName:NSDragPboard];
[pb setData:RTFDdata forType:NSRTFDPboardType];
[pb setData:RTFdata forType:NSRTFPboardType];
[attrStr release];
[super close];
}
I figure that seeing as the user cannot close the
document in the middle of a drag, and therefore
whatever happens, when the document is closed the drag
and drop must have finished, I may as well just paste
some blank data to the dragging pasteboard of the
promised types (RTF and RTFD in this case). This
prevents the crashes.
I'm not sure if this is the best way of doing things.
Is there ever a case where the drag pasteboard might
be accessed *after* a drag has finished? I could
retain the views as you suggest, but I don't really
want the document to stay open in the background at
all if the user has closed it...
Many thanks,
Keith
--- Steven Kramer <email@hidden> wrote:
> > So far, so good. But this setup is causing me
> crashes.
> > It seems that if I do any sort of drag operation
> in my
> > outline view, and then close the docoment window,
> > MyDocument does not get released. This means that
> > dealloc is never called, and consequently,
> MyDocument
> > is never unregistered as an observer. Thus, the
> closed
> > MyDocument may receive and act on a notification,
> and
> > its methods may try to access a view that *has*
> been
> > released when the window was closed - which
> results in
> > a crash.
> >
>
> I'd say the document needs to retain the view if it
> depends on it for
> correct behaviour. I may be oversimplifying, because
> I don't know the
> context, though.
>
> Regards
>
> Steven
>
>
__________________________________
Do you Yahoo!?
Yahoo! Mail - Helps protect you from nasty viruses.
http://promotions.yahoo.com/new_mail
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden