The garbage collector invokes this method on the receiver before disposing of the memory it uses.
- iOS 2.0–10.0Deprecated
- macOS 10.4–10.12Deprecated
- tvOS 9.0–10.0Deprecated
- watchOS 2.0–3.0Deprecated
- Objective-C Runtime
The garbage collector invokes this method on the receiver before disposing of the memory it uses. When garbage collection is enabled, this method is invoked instead of
You can override this method to relinquish resources the receiver has obtained, as shown in the following example:
Typically, however, you are encouraged to relinquish resources prior to finalization if at all possible. For more details, see Implementing a finalize Method.
It is an error to store
self into a new or existing live object (colloquially known as “resurrection”), which implies that this method will be called only once. However, the receiver may be messaged after finalization by other objects also being finalized at this time, so your override should guard against future use of resources that have been reclaimed, as shown by the
log statement in the example. The
finalize method itself will never be invoked more than once for a given object.