Deinit method is never called – Swift playground

Xcode’s Playgrounds for Swift don’t work like regular apps; they aren’t being run just once. The objects created stay in memory and can be inspected until you change the code, at which point the whole playground is reevaluated. When this happens, all previous results are discarded and while all object will be deallocated, you won’t see any output from that.

Your code is correct, but Playgrounds is not suited to test things related to memory management.

Here’s a related SO question: Memory leaks in the swift playground / deinit{} not called consistently

Leave a Comment