Understanding deinitialization and its customization
At some specific times, our app won't need to work with an instance anymore. For example, once you calculate the perimeter of a regular hexagon and display the results to the user, you don't need the specific RegularHexagon
instance anymore. Some programming languages require you to be careful about leaving live instances alive, and you have to explicitly destroy them and deallocate the memory that it consumed.
Swift uses an automatic reference counting, also known as ARC, to automatically deallocate the memory used by instances that aren't being referenced anymore. When Swift detects that you aren't referencing an instance anymore, Swift executes the code specified within the instance's deinitializer before the instance is deallocated from memory. Thus, the deinitializer can still access all of the instance's resources.
Note
You can think of deinitializers as equivalents of destructors in other programming languages such as C# and Java....