Re: Init method needed? + Dealloc method needed?
Re: Init method needed? + Dealloc method needed?
- Subject: Re: Init method needed? + Dealloc method needed?
- From: Michèle Garoche <email@hidden>
- Date: Mon, 24 Jun 2002 23:30:14 +0200
Le lundi 24 juin 2002, ` 03:58 , email@hidden a icrit :
If you REALLY don't have ANY initialization of any other objects (rare
but certainly true) / data structures
than there is no reason that I can see to override the -init method..
likewise, if you don't alloc / retain any objects there is no reason to
override -dealloc either..
Apart from the mainmenu.nib, which contains a window with three
NSImageViews and a drawer with a tabView (NSTextFields and NSSliders
inside it), there is another nib for the aboutBox.
A - I suppose, I may be wrong, the mainmenu.nib is loaded
automatically at launch time as it is the controller of the app.
In the awakeFromNib method:
1 - I set the values for sliders and text fields (outlets), load two
images (in main bundle).
2 - Draw the images into the NSImageViews and a resulting image (draw
methods are also in the controller) with affine transforms. I use
temporary images at draw time, released in the methods
3 - Set up the toolbar (declare in a category of the controller)
At this time, I have (is it true?) two NSImage and two NSAffineTransform.
In the applicationDidFinishLaunching methods:
I just open the drawer.
So, is there anything to init here?
B - A shared instance of the AboutBox is created when the user clicks on
the corresponding menu item.
There is an init method here that dealloc the instance if it already
exists, creates it otherwise.
A timer is initialized when the window become key and is invalidated
when the window resigned key.
-dealloc is automagically called when the object is no longer in use..
The rule of thumb (and a good rule it is), if an instance of your class
retain's any other objects
then you need (read: really really should) create a -dealloc routine to
release those objects ..
On a first approach, I wrote a dealloc method in the mainmenu nib for
NSImage.
The big problem is where should I put the dealloc method for the shared
instance ( I need it in the mainmenu to check if the about box is open
before quitting)?
However, those are both pretty darn rare circumstances if any
application of interest.. :-)
Of course, my app is of no interest to anyone, but me :-)))
It is just a little app to create icons with tiff so that I can
customize my folders for free. A way to teach me Cocoa and incidentally
to have folders I can recognize.
If someone wants to check the code and makes any comments about it, it
would be greatly appreciated. It is at:
<
http://212.11.38.139/cocoa>
Michhle
_______________________________________________
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.