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

[SR-1339] switch statement memory leak (again) #43947

Closed
swift-ci opened this issue Apr 27, 2016 · 5 comments
Closed

[SR-1339] switch statement memory leak (again) #43947

swift-ci opened this issue Apr 27, 2016 · 5 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself memory leak bug: Memory leak

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-1339
Radar None
Original Reporter ata_n (JIRA User)
Type Bug
Status Resolved
Resolution Cannot Reproduce

Attachment: Download

Environment

MacBook Pro (Retina, 15-inch, Late 2013),
2 GHz Intel Core i7,
8 GB 1600 MHz DDR3,
Xcode 7.3

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, Leak
Assignee ata_n (JIRA)
Priority Medium

md5: 7e9b79a33bb9f7fde7e2605312aa8d54

Issue Description:

There was a bug fixed with the release of Xcode 7.1:

  • Using switch against multiple types with as patterns no longer causes a memory leak. (22587077)

I have found that this bug still persists in Xcode 7.3, however this time it is occurring in switch statements with pattern matching regarding enums with associated values. Since switch statements are the only method of accessing associated values inside enum cases there is no good rewrite with if statements. The problem exists only when there are more 5 or 6 cases in the switch statement with each case using pattern matching to capture the associated value.

For the time being I have resolved the memory leak by having smaller switch statements in separate funcs that take in parameters by reference (inout). This does solve the memory leak. However this isn't a clean solution and it feels to me very much like the bug found in previous versions of Xcode using as pattern matching.

Thank you

@belkadan
Copy link
Contributor

I think we just fixed something like this. @swiftix, @jckarter?

@jckarter
Copy link
Member

ata_n (JIRA User) Can you attach an example program that reproduces the leak?

@swift-ci
Copy link
Collaborator Author

Comment by Ata (JIRA)

I tried replication a scenario close to what I was experiencing. You can see the leak in Instruments.
Note that commenting lines 51 through 79 (removing four of the cases) will not result in a leak.

Thanks guys

@swift-ci
Copy link
Collaborator Author

Comment by Edwin Vermeer (JIRA)

I am having the same issue in Xcode 7.3.1
Details can be found here: http://stackoverflow.com/questions/37333456/memory-leak-using-case-let-x-y-as-nsstring

I was able to fix the issue by converting the code to an if fall-through. The fixed code can be found here:
https://github.com/evermeer/EVReflection/blob/master/EVReflection/pod/EVReflection.swift#L617

If you want to replicate the issue, then you could download EVReflection, change the fixed code back to the code that I reported on stackoverflow and then run the test project.

@eeckstein
Copy link
Member

I could not reproduce the leaks with the attached file and with the function in EVReflection with a recent swift 3 compiler.
I attached the reduced test from EVReflection, converted to swift 3 syntax.
We fixed a few bugs which are most likely the cause for this leak. Some of these bug fixes are already included in the latest Xcode 8 beta. Some were done recently and will be included in an upcoming release.

Please let me know if you still see this problem with the swift 3 compiler.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself memory leak bug: Memory leak
Projects
None yet
Development

No branches or pull requests

4 participants