Swift Deinitialization of Globals
ios, swift
Solution
it looks fine to me... on ending the app nothing is deallocated - there is no point
deinit is only meant to FREE memory and remove observers and stuff - upon ending the process though, this is kinda 'useless' as the process memory 'will be wiped' anyways
==>
SO:
never put anything but memory management / observer related stuff in deinit
If you need a dedicated stop method - write one and call it explicitly before quitting the process
Problem
My Swift globals are not getting deinitialized. ``` class Person { let name: String init(name: String) { self.name = name println("\(name) is being initialized") } deinit { println("\(name) is being deinitialized") } } func local() { let person = Person(name: "Local") } local() var personp: Person? = Person(name: "Optional Global") personp = nil var person = Person(name: "Global") ``` I am running this in a standalone binary (because apparently the playground has issues with deinit) with optimizations disabled, using Xcode6-Beta3: ``` > xcrun swift -O0 arc.swift && ./arc Local is being initialized Local is being deinitialized Optional Global is being initialized Optional Global is being deinitialized Global is being initialized ``` Note the missing Global is being deinitialized. I can't even figure out if this is expected behaviour or a bug, so if it is the former then references to the relevant legalese will be appreciated.