memory leaks - Swift / SpriteKit - Can't break strong reference cycle -
i completed spritekit game without having knowledge of strong reference cycles. i'm not having crashes or obvious problems, using instruments can see objects being retained between each level (skscene should dealloced between levels).
here general pieces of game:
gameconfig
static struct
i have globally accessible static struct references viewcontroller. access viewcontroller using struct on app. assign gameconfig.viewcontroller = self
inside of viewcontroller's viewdidload
gameviewcontroller
in here reference skscene, , skview such
var skview: myview! weak var scene: skscene!
basescene
this base skscene class. property of class gets reference class itself
let indicators: indicators = indicators()
killscene
subclass of basescene
in basescene subclass, have many custom subclasses contained in arrays. these custom subclasses reference scene, scene not referencing them directly. has reference container array. example:
var radarblips: [radarblip] = []
i have 1 property has strong reference cycle killscene
var ship: killship = killship()
in both indicators
, killship
classes, have referenced scene using weak
keyword.
in fact have found every instance reference scene, , put weak
in front of it.
i tried make stripped down game, , create strong reference cycle between sprite , scene, , break it. successful in doing so. can't seem debug own game.
any detailed suggestions helpful. know there's trickiness passing closures around. maybe has it? advice on great. i've put weak
in more places need to.
i can not scene deinit
there wasn't easy way this. check properties reference eachother , use weak or unowned. bigger issue in spritekit checking closures. when you're running delayed closures (in skactions) , things it's important use [weak self]
within closure doesnt keep object alive. it's easier add more weaks , unowned necessary until strong reference cycle broken , work way backwards deleting unnecessary ones.