Re: NSView subclass never gets dealloced?
Re: NSView subclass never gets dealloced?
- Subject: Re: NSView subclass never gets dealloced?
- From: "Erik M. Buck" <email@hidden>
- Date: Fri, 29 Mar 2002 21:21:02 -0600
- Organization: EMB & Assocites Inc.
>
> 1) NSWindowController releases top level objects in associates nibs.
>
> If you
>
> are not using NSWindowController then you must release them yourself.
>
>
I'm assuming that "not using NSWindowController" means not using a
>
subclass? A default controller is created for you if you have a one
>
window nib file, correct?
No. Instances of the NSDocument class create instances of
NSWindowController. You can override NSDocument methods to get NSDocument
to use a subclass of NSWindowController. If you do not use the NSDocument
class and you do not create NSWindowController instances yourself, then
there are no instances of NSWindowController in your application.
>
>
> 2) Normal reference counted memory management applies. If you retain a
>
> view
>
> and do not correspondingly release it, YOU have created a memory leak
>
> and it
>
> is not the frameworks fault.
>
>
Sure. I definitely release any subviews that I create programmatically.
>
I alloc and init, addSubview then release, letting the superview retain
>
it. It's then up to Cocoa to release subviews when the superview goes
>
away, right?
Right.
>
>
> 3) The IB option to release on close exists to support the situation in
>
> which NSWindowController is not used. Using that option in combination
>
> with
>
> NSWindowController probably produces too many releases.
>
>
For Jonathan Wight's initial question, if you create a new Cocoa app
>
project, add a custom view to the window, create an NSView subclass, set
>
the custom view to that subclass, then add the following code to the
>
subclass implementation, the dealloc never gets called.
>
>
@implementation MyView
>
>
-(id)initWithFrame:(NSRect)aRect
>
{
>
NSLog(@"initWithFrame:");
>
self = [super initWithFrame:aRect];
>
if(self)
>
{
>
// blah, blah, blah
>
}
>
return self;
>
}
>
>
-(void)dealloc
>
{
>
NSLog(@"dealloc:");
>
[super dealloc];
>
}
>
>
@end
I think dealloc is called in the case you describe if the window is
realeased when closed. Quiting an application may not automatically close
all open windows, but I think it does. NSApplication maintains a list of
windows that belong to the application.
>
>
You have to check the "Release when closed" button in IB for it to be
>
properly dealloc'ed. I think my problem with the app crashing with this
>
option checked is that I have a couple of floating windows and one main
>
window, and the default window controller appears to only support one
>
window. The presence of more than one window appears to be what caused
There is no default window controller unless NSDocument is used or you
created the window controller yourself. It is more likely that you are
keeping a pointer to a dealloced window and trying to use the pointer.
Don't do that.
>
the crash I saw. Our app is in no way finished so I'm not intent on
>
leaving it this way, but that's the state it's currently in. I'll start
>
on a NSWindowController subclass to do it right.
>
[Deleted]
>
I've grown up doing Toolbox development with the original InsideMac
>
series which is wonderful. The later docs are not as good as the
>
original series, but they're not bad. However, the Cocoa docs are still
>
lacking examples. It's odd that O'Reilly does a starter book on
>
development, but Apple doesn't have their own, even with 13+ years of
>
Next history. It doesn't take long to outgrow the O'Reilly book either,
Well, you can buy the book that I co-wrote.
>
so now I'm looking for those examples of extracting glyph outlines from
>
fonts, getting PDF information from files into a graphics context as
I posted just such an example of getting the outline path of a glyph to this
forum months ago. There is also the CircleView example from Apple that does
this. Parsing PDF is non-trivial. Consider using XML and open standards
instead. (SVG)
>
vectors rather than an imaged pixmap, and ways to save PDF data to a
>
file using Cocoa rather than the Adobe library or a gnu library. Which
NSView provides the ability to save vector graphics in PDF files. Every
Cocoa application has this capability.
_______________________________________________
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.