# Why retain/release pair is not removed in this particular case?

**URL:** <https://forums.swift.org/t/why-retain-release-pair-is-not-removed-in-this-particular-case/77206>\
**Category:** Using Swift\
**Tags:** performance, optimizations, arc\
**Created:** [January 15, 2025, 12:35am UTC](https://forums.swift.org/t/why-retain-release-pair-is-not-removed-in-this-particular-case/77206 "2025-01-15T00:35:35Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![Karl](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@Karl](https://forums.swift.org/u/Karl)\
**Post date:** [January 15, 2025, 8:17pm UTC](https://forums.swift.org/t/why-retain-release-pair-is-not-removed-in-this-particular-case/77206/3 "2025-01-15T20:17:34Z")

</div>

This is because `for` loops use consuming iteration, which needs to copy the array. There are two ways to solve this:

1. A smarter optimiser. If you compile with `-Xfrontend -enable-ossa-modules`, the copy gets optimised away, and the `d` function does not contain any retains or releases.

2. Use an index-based loop instead:

---

_[View the full topic](https://forums.swift.org/t/why-retain-release-pair-is-not-removed-in-this-particular-case/77206)._
