Swift Deinitialization is a process where 'deinitializer' is called to deallocate the memory space before a class instance deallocated. The'deinit' keyword is used to deallocate the memory spaces occupied by the system resources. Deinitialization is available only on class types.
How Deinitialization Works
Swift automatically deallocates instances which are no longer needed, to free up resources. Swift uses Automatic Reference Counting (ARC) to handle the memory management of Instances. Usually, you don?t need to perform manual cleanup when your instances are deallocated. But, when you work with your own resources, you need to perform some additional cleanup.
For example: If you create a custom class to open a file and write some data to it, you might need to close the file before the class instance is deallocated.
Swift Deinitialization Example
Here, print = nil statement values of the counter retains the same since it is not deinitialized.
Next TopicSwift Initialization