Swift Object ModelLesson 34Free preview
Deinitializers
This lesson is part of Swift · All levels
Summary
This lesson discusses Deinitializers in Swift that are declared with the keyword 'deinit'. The Deinitializer is automatically called by the system just before the class instance is destroyed and its memory heap is released by the ARC. This feature is very useful for clearing resources such as closing files or cancelling the observer.
Key points
- Deinitializer is declared with the keyword 'deinit {...}'
- Available only for Reference Type (Class), not available for Struct or Enum
- Called automatically by the system when the reference count of the object reaches zero
- Ideal for cleaning out external resources (closing file handle, removing notification observer)
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.