sohail.io

  • About

Swift Memory Management Exercise

June 21, 2015

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

My Solution to the Memory Management Exercise

Filed Under: iOS Tagged With: arrays, memory management, optionals, raywenderlich.com, retain cycles, swift, weak

search

Categories

  • General
  • iOS

Recent Posts

  • AppleScript Export to CSV via iWork Numbers
  • Verifying the Status of an Auto-Renewable Subscription
  • Swift Memory Management Exercise
  • Learning Swift: My Approach
  • UIAutomation Command Line Test Runner for Xcode 6

This Blog

My name is Sohail. I'm a developer-consultant and entrepreneur primarily focused on building high quality iOS apps.

I write about software development. Mostly iOS related and sometimes, Ruby on Rails.

See the About page for more bio.

Sohail Ahmed - About page for blog author bio

Category Specific RSS

  • General (2)
  • iOS (6)

Archives

  • October 2015 (2)
  • June 2015 (2)
  • September 2014 (1)
  • October 2013 (3)

Copyright © 2021 Sohail A. · Log in

All opinions expressed are strictly those of the author, and do not necessarily reflect those of guests, partners, sponsors, customers or affiliates.