# Confirming order of operations

**URL:** <https://forums.swift.org/t/confirming-order-of-operations/16376>\
**Category:** Using Swift\
**Created:** [September 22, 2018, 8:51pm UTC](https://forums.swift.org/t/confirming-order-of-operations/16376 "2018-09-22T20:51:44Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![Joe\_Groff](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/joe_groff/32/1929_2.png) [@Joe\_Groff](https://forums.swift.org/u/Joe_Groff)\
**Post date:** [September 24, 2018, 8:23pm UTC](https://forums.swift.org/t/confirming-order-of-operations/16376/9 "2018-09-24T20:23:37Z")

</div>

This isn't guaranteed. Releases may be optimized to happen earlier than this, to any point after the last formal use of the strong reference. Since the strong reference loaded in order to evaluate the left-hand side `weakProperty?.variable` is not used afterward, there is nothing keeping it alive, so it could be immediately released. If there are any side effects in the getter for `variable` that cause the object referenced by `weakProperty` to be deallocated, nil-ing out the weak reference, then that would cause the force-unwrap on the right side to fail. You should use `if let` to test the weak reference, and reference the strong reference bound by the `if let`:

```swift
if let property = weakProperty {
  property.variable = property.otherVariable
  property.performMethod(property)
}

```

This should safer and also more efficient, since the weak reference is loaded and tested once instead of four times.

---

_[View the full topic](https://forums.swift.org/t/confirming-order-of-operations/16376)._
