FROM : Nir Soffer
DATE : Thu Jun 22 21:10:59 2006
On 22/06/2006, at 20:12, D.K. Johnston wrote:
> I have a text view in a window and a controller class that manages
> it. There is a one-to-one correlation between these controllers and
> their windows. The controller object is the delegate of the window,
> and it's told to releases itself when the window closes.
>
> My question is: Should I use a +init factory method to instantiate
> the class, instead of the usual [[alloc] -init] procedure?
Do you mean +object... convenience methods? e.g [NSString string]
>
> I _think_ the answer is "yes", since I should never send a release
> message to any of these objects; but I'd feel better if I had an
> expert second opinion.
It does not matter how you create the object - if you use alloc init,
you have to release it at the end, and if you use a connivence
method, you have to retain the object, and then release it at the
end :-)
The real answer is to read this:
https://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/
MemoryMgmt.html
Best Regards,
Nir Soffer
DATE : Thu Jun 22 21:10:59 2006
On 22/06/2006, at 20:12, D.K. Johnston wrote:
> I have a text view in a window and a controller class that manages
> it. There is a one-to-one correlation between these controllers and
> their windows. The controller object is the delegate of the window,
> and it's told to releases itself when the window closes.
>
> My question is: Should I use a +init factory method to instantiate
> the class, instead of the usual [[alloc] -init] procedure?
Do you mean +object... convenience methods? e.g [NSString string]
>
> I _think_ the answer is "yes", since I should never send a release
> message to any of these objects; but I'd feel better if I had an
> expert second opinion.
It does not matter how you create the object - if you use alloc init,
you have to release it at the end, and if you use a connivence
method, you have to retain the object, and then release it at the
end :-)
The real answer is to read this:
https://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/
MemoryMgmt.html
Best Regards,
Nir Soffer
| Related mails | Author | Date |
|---|---|---|
| D.K. Johnston | Jun 22, 19:12 | |
| Nir Soffer | Jun 22, 21:10 |






Cocoa mail archive

