Apple Enterprise - NeXTanswers Support Archive

Search NeXTanswers for:


Title: Releasing EOControllers in nibs

Entry Number:

Last Updated: 19 Apr 1995
Document Revision:

EOF, EOController, nib, release, autorelease, retain count


Q: I have several EOControllers in my nib. I noticed that immediately after loading the nib, some of them have a retain count of 1 and some have a higher count. I use this nib frequently and want to make sure that the EOControllers are released when I am done with it. What do I have to do?


A: When the nib is loaded, each EOController is created with a retain count of 1. Since you loaded the nib, you are responsible for releasing them. When you are done with the nib, for example when the main window is closed, you should release each EOController (and all other objects in the nib that won't be freed) once either with release.

You may find that detail and qualified-peer EOControllers have a higher retain count when the nib is first loaded. This is because the master controllers retain their detail controllers (actually they have EOAssociations which retain the detail EOControllers). But you should not be concerned with this, just release each controller once and they will all be freed. The master EOController will release it's associations which will subsequently release the detail controllers.

If you have a Window that is set to be "free when closed" that contains UI objects (i.e. TextField, Form, etc) used by a controller's associations, the UI objects are freed when the window is freed. This will cause a problem since the associations will try to free the UI objects when they are freed, but if they are freed already the app will crash. In this instance, don't use the "free when closed" mechanism, but rather respond to the windowWillClose: delegate message and autorelease the Window object. You should still release each EOController object once.

Valid for: EOF 1.0, EOF 1.1, NEXTSTEP 3.2 Developer, NEXTSTEP 3.3 Developer

OpenStep | Alliances | Training | Tech Support | Where to Buy