I’ve covered my approach to learning Swift in an earlier post.
In this post, I wanted to post my solution to an exercise in the Intermediate Swift Tutorial Series video for Memory Management (Part 9), available at RayWenderlich.com. Note that you’ll need to be a paying subscriber to access the video tutorial page.
The exercise challenges the reader to create an object graph avoiding retain cycles, noting that Swift Array objects, like in many reference counted languages, will have strong references to all of their elements.
You’ll need to review the actual tutorial challenge for context (that’s copyright material I won’t reproduce here). However, if you’ve followed along, you’ll know that the posted solution playground doesn’t actually demonstrate or prove to the reader that there are no retain cycles.
As such, I set out to answer the exercise in a way that would give me that tangible satisfaction that the full object graph had gotten deallocated.
You can access the full contents of my solution playground from this gist.
As you can see below, when I set the rwDevCon variable to nil, it sets off the chain of visible deallocation.
You can also download a zip archive of the Xcode 7 Beta 1 playground that I used to complete the exercise from the Ray Wenderlich tutorial here: MyLearningPart09.playground.zip