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-14121] Memory leak when destructuring a mirror's child #56502

Open
stephencelis opened this issue Jan 28, 2021 · 1 comment
Open

[SR-14121] Memory leak when destructuring a mirror's child #56502

stephencelis opened this issue Jan 28, 2021 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@stephencelis
Copy link
Contributor

Previous ID SR-14121
Radar rdar://problem/73770096
Original Reporter @stephencelis
Type Bug
Environment

Xcode 12.3 (Swift 5.3)

Additional Detail from JIRA
Votes 3
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 99dfde31239a799123e9cf2aefe1aa07

Issue Description:

The following code causes a memory leak:

func foo() {
  struct A {
    var a = "hello"
    var b = B()
    struct B {
      var c = "world"
    }
  }

  if case (_?, _)? = Mirror(reflecting: [A()]).children.first {
  }
}

Call foo() from the body of a SwiftUI app, in applicationDidFinishLaunching, a main.swift executable, etc., to see. Then run the app, open the memory graph debugger, and you will see a 48 byte malloc leak.

The layout of type A, the reflection on an array of the same type and the destructuring pattern all seem to contribute to the leak. If any of these things changes slightly, the leak goes away.

@typesanitizer
Copy link

I wonder if it could be related to this issue: https://bugs.swift.org/browse/SR-13926

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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
Projects
None yet
Development

No branches or pull requests

2 participants