99
/** This is an informal protocol ... classes may implement the method and
100
* register themselves to have it called on process exit.
102
@interface NSObject(GSAtExit)
103
/** This method is called on exit for any class which implements it and which
104
* has called +registerAtExit to register it to be called.<br />
105
* The order in which methods for different classes is called is the reverse
106
* of the order in which the classes were registered, but it's best to assume
107
* the method can not depend on any other class being in a usable state
108
* at the point when the method is called (rather like +load).<br />
109
* Typical use would be to release memory occupied by class data structures
110
* so that memory usage analysis software will not think the memory has
116
/** Category for methods handling leaked memory cleanup on exit of process
117
* (for use when debugging memory leaks).<br />
118
* You enable this by calling the +setShouldCleanUp: method (done implicitly
119
* by gnustep-base if the GNUSTEP_SHOULD_CLEAN_UP environment variable is
121
* Your class then has two options for performing cleanup when the process
123
* <p>1. Use the +leak: method to register objects which are simply to be
124
* retained until the process ends, and then either ignored or released
125
* depending on the cleanup setting in force. This mechanism is simple
126
* and should be sufficient for many classes.
128
* <p>2. Implement a +atExit method to be run when the process ends and,
129
* within your +initialize implementation, call +shouldCleanUp to determine
130
* whether cleanup should be done, and if it returns YES then call
131
* +registerAtExit to have your +atExit method called when the process
134
* <p>The order in which 'leaked' objects are released and +atExit methods
135
* are called on process exist is the reverse of the order in which they
136
* werse set up suing this API.
139
@interface NSObject(GSCleanup)
142
/** This method simply retains its argument so that it will never be
143
* deallocated during normal operation, but keeps track of it so that
144
* it is released during process exit if cleanup is enabled.<br />
145
* Returns its argument.
147
+ (id) leak: (id)anObject;
149
/** This method retains the object at *anAddress so that it will never be
150
* deallocated during normal operation, but keeps track of the address
151
* so that the object is released and the address is zeroed during process
152
* exit if cleanup is enabled.<br />
153
* Returns the object at *anAddress.
155
+ (id) leakAt: (id*)anAddress;
157
/** Sets the receiver to have its +atExit method called at the point when
158
* the process terminates.<br />
159
* Returns YES on success and NO on failure (if the class does not implement
160
* the method or if it is already registered to call it).<br />
161
* Implemented as a call to +registerAtExit: with the selector for the +atExit
162
* method as its argument.
164
+ (BOOL) registerAtExit;
166
/** Sets the receiver to have the specified method called at the point when
167
* the process terminates.<br />
168
* Returns YES on success and NO on failure (if the class does not implement
169
* the method ir if it is already registered to call it).
171
+ (BOOL) registerAtExit: (SEL)aSelector;
173
/** Specifies the default cleanup behavior on process exit ... the value
174
* returned by the NSObject implementation of the +shouldClanUp method.<br />
175
* Calling this method with a YES argument implicitly calls the +enableAtExit
176
* method as well.<br />
177
* The GNUstep Base library calls this method with the value obtained from
178
* the GNUSTEP_SHOULD_CLEAN_UP environment variable when NSObject is
181
+ (void) setShouldCleanUp: (BOOL)aFlag;
183
/** Returns a flag indicating whether the receiver should clean up
184
* its data structures etc at process exit.<br />
185
* The NSObject implementation returns the value set by the +setShouldCleanUp:
186
* method but subclasses may override this.
188
+ (BOOL) shouldCleanUp;
99
192
#endif /* OS_API_VERSION */
101
194
#if defined(__cplusplus)