Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

26366199: Swift interpolated strings leaking memory #14718

Open
openradar-mirror opened this issue May 19, 2016 · 2 comments
Open

26366199: Swift interpolated strings leaking memory #14718

openradar-mirror opened this issue May 19, 2016 · 2 comments

Comments

@openradar-mirror
Copy link

openradar-mirror commented May 19, 2016

Description

Summary:
Using interpolated strings in Swift can cause memory leaks to be reported in Instruments. Changing the code from interpolating to concatenating the strings fixes the leak.

I’ve attempted to shrink the repro case down as much as I can, from what I can gather, the problem only occurs when a largish value type is assigned within the same scope. There are other factors involved that I couldn’t discern - making minor changes to the size/structure of the value types can result in the leak disappearing, but the structure I’ve supplied in the sample code will reproduce the issue every time.

Note the types need to be declared in a separate file, and the code compiled -O (fast) with whole module optimisations off.

The relevant code is also available at https://gist.github.com/samritchie/81172456003141415f2fddcd4d3e50e9 if there’s an issue with the zip.

Steps to Reproduce:

  1. Download the attached project zip and unzip
  2. Open in Xcode and select a simulator or device
  3. Profile the app in Instruments, selecting the 'Leaks' instrument if prompted (Simulator or Device is okay)
  4. Comment out the string interpolation at AppDelegate.swift#20 and uncomment the concatenation at 22098225: Add indexOfObject:inSortedRange:options:usingComparator: method in Swift Array #23
  5. Profile the app again

Expected Results:
There shouldn’t be any memory leaks, regardless of whether interpolation or concatenation is used

Actual Results:
Instruments detects a memory leak in the interpolation case

Version:
Xcode Version 7.3.1 (7D1014)
OS X 10.11.4 (15E65)
Apple Swift version 2.2 (swiftlang-703.0.18.8 clang-703.0.31)

Notes:

Configuration:
Apple Swift v 2.2 (Xcode 7.3.1). I’ve only tested iOS/iOS Simulator and this specific version of Swift.

Product Version:
Created: 2016-05-19T11:50:04.978650
Originated: 2016-05-19T19:45:00
Open Radar Link: http://www.openradar.me/26366199

@openradar-mirror
Copy link
Author

Modified: 2016-05-19T11:50:04.978900

1 similar comment
@openradar-mirror
Copy link
Author

Modified: 2016-05-19T11:50:04.978900

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant