Apple Enterprise - NeXTanswers Support Archive
Enterprise
[Index]
[Download]


Search NeXTanswers for:

NEXTSTEP


Title: Using NSAutoreleasePool without EOF

Entry Number:
1722
Last Updated: April 28 1995
Document Revision:

Keywords:
Foundation, EOF, NSAutoreleasePool

Question


Q: I have an application that uses Foundation but not EOF. I understand that the EOApplication class has support for NSAutoreleasePools, and without this any objects in my application that are autoreleased may not ever be freed. But I don't want to have to depend on EOF. What can I do?

Answer


A: An easy way to provide autorelease support for your application is to create an NSAutoreleasePool instance before every event and release it after. You can implement your own Application subclass that does this, some example code is below. Note that during modal loops, many events can transpire, so you need to disable the releasing of the NSAutoreleasePool during modal loops or the objects involved in the modal session might get freed prematurely. A similar problem occurs with getNextEvent: and getNextEvent:waitFor:threshold:.
PoolApplication.[hm]:

Note that if you do not implement this or a similar mechanism for creating autorelease pools, all objects that are autoreleased may not ever be freed which can lead to your application having lots of serious memory leaks. If your application uses EOF, it is simpler and more robust to set your application class EOApplication. This detailed in the EOF documentation in EnterpriseObjects/Guide/Part2_AppDesign.

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


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