I was just playing with leaks and tried to create one intentionally. So, even it is silly to do something like this:
class LeakingObjectA{
var strongRefToB:LeakingObjectB?
deinit{ print("LeakingObjectA deinit")}
}
class LeakingObjectB{
var strongRefToA:LeakingObjectA?
deinit{ print("LeakingObjectB deinit")}
}
it is fine for the science purposes, and this creates a strong reference cycle.
Now inside didMoveToView I declare local constants and make a leak like this:
override func didMoveToView(view: SKView) {
let a = LeakingObjectA()
let b = LeakingObjectB()
a.strongRefToB = b
b.strongRefToA = a
}
After a transition to another scene, the scene's deinit is called properly, but deinits from a and b instances are not actually called.
Also I say leak because this is actually detected in instruments as a leak:
Now there is a difference between what Instruments detect as leak if I declare these two local vars as properties of a scene:
class GameScene:SKScene {
let a = LeakingObjectA()
let b = LeakingObjectB()
//...later in didMoveToView method I make a strong reference cycle like from the example above
}
Of course in this case, the scene's deinit is called as well after the transition, and same as above, deinits from a and b instances are not called (because of strong reference cycle).
Still, this is not detected as leak in Instruments... So what would be the reasonable explanation for this ?
