# ARC and Memory Management in Swift

**URL:** <https://forums.kodeco.com/t/arc-and-memory-management-in-swift/19774>\
**Category:** 🎓 Courses & Articles\
**Created:** [September 14, 2016, 4:02pm UTC](https://forums.kodeco.com/t/arc-and-memory-management-in-swift/19774 "2016-09-14T16:02:39Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![eastprogrammer](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/eastprogrammer/32/52384_2.png) [@eastprogrammer](https://forums.kodeco.com/u/eastprogrammer)\
**Post date:** [September 14, 2016, 4:02pm UTC](https://forums.kodeco.com/t/arc-and-memory-management-in-swift/19774/1 "2016-09-14T16:02:39Z")

</div>

Ever wondered how memory management works in Swift? Or what common pitfalls are? Take a dive into ARC and memory management in Swift with this tutorial.

* * *
 This is a companion discussion topic for the original entry at [https://www.raywenderlich.com/959-arc-and-memory-management-in-swift](https://www.raywenderlich.com/959-arc-and-memory-management-in-swift)

---

<div class="post-metadata">

**Author:** ![faircoder](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/faircoder/32/102075_2.png) [@faircoder](https://forums.kodeco.com/u/faircoder)\
**Post date:** [September 16, 2016, 9:01pm UTC](https://forums.kodeco.com/t/arc-and-memory-management-in-swift/19774/2 "2016-09-16T21:01:05Z")

</div>

Wow! incredibly eye-opening material regarding memory management. This is going straight to my cheat sheet playgrounds folder. One question regarding the use of reference types for the Node class. In a recent tutorial on the site, the author created a binary tree in Swift.

Tutorial - [https://www.raywenderlich.com/139821/swift-algorithm-club-swift-binary-search-tree-data-structure](https://www.raywenderlich.com/139821/swift-algorithm-club-swift-binary-search-tree-data-structure)

The author replaced a node class similar to the one you defined by creating an enum with the indirect keyword specified to build the tree structure. To me this seemed to be forcing the use of value types when the use case seemed to call for a reference type. Does one approach or the other have a clear advantage when taking memory management into consideration?

---

<div class="post-metadata">

**Author:** ![jsd](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/jsd/32/81494_2.png) [@jsd](https://forums.kodeco.com/u/jsd)\
**Post date:** [September 21, 2016, 5:49pm UTC](https://forums.kodeco.com/t/arc-and-memory-management-in-swift/19774/3 "2016-09-21T17:49:14Z")

</div>

Awesome tutorial on reference cycles! I would love to see more about this subject with real world examples and how to troubleshoot them. Thank you.

---

<div class="post-metadata">

**Author:** ![eastprogrammer](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/eastprogrammer/32/52384_2.png) [@eastprogrammer](https://forums.kodeco.com/u/eastprogrammer)\
**Post date:** [September 24, 2016, 6:37pm UTC](https://forums.kodeco.com/t/arc-and-memory-management-in-swift/19774/4 "2016-09-24T18:37:59Z")

</div>

Hi faircoder! Thanks for the positive feedback!

The choice between a reference type or a value type depends on the situation. Generally, Swift favors structs over classes for multiple reasons:

- Structs are allocated on the Stack instead of on the Heap, which makes them considerably faster.
- They’re more ‘intuitive’: you never have to worry about them being changed in one place and in another one at the same time
- And of course: no memory leaks… :]

In this tutorial, I added the ‘Node’ example to illustrate that reference cycles with structs are impossible because of their non-recursive nature.

But again, the choice between a reference or value type is dependent on each unique case. Reference types have features like the one illustrated in this tutorial; namely the fact that they disappear when they’re not referenced anymore, that can be useful in some situations.

---

<div class="post-metadata">

**Author:** ![yataiblue](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/yataiblue/32/81494_2.png) [@yataiblue](https://forums.kodeco.com/u/yataiblue)\
**Post date:** [December 13, 2016, 4:17am UTC](https://forums.kodeco.com/t/arc-and-memory-management-in-swift/19774/5 "2016-12-13T04:17:30Z")

</div>

Excellent article!

I am a 51 year-old programming beginner.  
I was so impressed by your teaching skill.  
I had been confused by choosing whether weak or unowned until I came across your article.

I translated this article Japanese and post it on my bolg[http://yataiblue.hatenablog.com/entry/2016/12/09/000000](http://yataiblue.hatenablog.com/entry/2016/12/09/000000)

Thank you!

---

<div class="post-metadata">

**Author:** ![rayfix](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/rayfix/32/108995_2.png) [@rayfix](https://forums.kodeco.com/u/rayfix)\
**Post date:** [December 13, 2016, 6:23pm UTC](https://forums.kodeco.com/t/arc-and-memory-management-in-swift/19774/6 "2016-12-13T18:23:24Z")

</div>

Hi yataiblue-san,

Let me update my comment because I was wrong. Ray does allow a limited number of translations with certain requirements which your blog meets! [https://www.raywenderlich.com/faq](https://www.raywenderlich.com/faq)

Sorry for the confusion! Thanks for your enthusiasm again.

---

<div class="post-metadata">

**Author:** ![sandeep007](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/sandeep007/32/65214_2.png) [@sandeep007](https://forums.kodeco.com/u/sandeep007)\
**Post date:** [December 22, 2016, 5:53pm UTC](https://forums.kodeco.com/t/arc-and-memory-management-in-swift/19774/7 "2016-12-22T17:53:24Z")

</div>

@eastprogrammer surprised to know your level of knowledge on Memory Management. Expecting more tutorials from you on this topic. Cheers!

---

<div class="post-metadata">

**Author:** ![renniepet](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/renniepet/32/59657_2.png) [@renniepet](https://forums.kodeco.com/u/renniepet)\
**Post date:** [February 11, 2017, 9:26pm UTC](https://forums.kodeco.com/t/arc-and-memory-management-in-swift/19774/8 "2017-02-11T21:26:55Z")

</div>

This is a totally off-topic comment, but may I suggest that you change your tutorial where you specify a telephone country code from “0032” to “+32”. That’s the correct way to specify country codes, and the “00” prefix is not universal - it’s different for use in many countries. So then you’ll help educate people about both ARC and the international telephone system. 🙂

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [October 16, 2017, 2:15pm UTC](https://forums.kodeco.com/t/arc-and-memory-management-in-swift/19774/9 "2017-10-16T14:15:55Z")

</div>

This tutorial is more than six months old so questions regarding it are no longer supported for the moment. We will update it as soon as possible. Thank you! :]

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [October 16, 2017, 2:15pm UTC](https://forums.kodeco.com/t/arc-and-memory-management-in-swift/19774/10 "2017-10-16T14:15:57Z")

</div>

Closed on October 16, 2017, 2:15pm UTC


