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-13926] switch statement on enum that have case with protocol type value causes memory leaks #56324

Closed
Gotyanov opened this issue Dec 2, 2020 · 2 comments
Assignees
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

@Gotyanov
Copy link

Gotyanov commented Dec 2, 2020

Previous ID SR-13926
Radar rdar://problem/71992652
Original Reporter @Gotyanov
Type Bug
Status Closed
Resolution Done
Environment

XCode 12.2 swift-DEVELOPMENT-SNAPSHOT-2020-12-01-a-osx

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, Leak
Assignee @gottesmm
Priority Medium

md5: 126331b9d3473787dbdb90a93fb11de0

Issue Description:

class Class {}
protocol Protocol {}

enum Enum {
    case value1(Class)
    case value2(Protocol)
}

var value: Class? = Class()
weak var weakValue: Class? = value

func leak(_ e: Enum?) {
    switch (e) {
    case .value2: return
    default: return
    }
}

leak(Enum.value1(value!))

value = nil

assert(weakValue == nil)

notes:
If to replace associated value in .value2 on non-existential type the problem disappears.
If to replace argument of leak() to non-optional the problem disappears.
If to comment out 'case .value2: return' the problem disappears.

@typesanitizer
Copy link

@swift-ci create

@gottesmm
Copy link
Member

Fixed in: #35093

@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

3 participants