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-9183] Memory leak in is type-casting pattern in switch #51674

Open
swift-ci opened this issue Nov 5, 2018 · 3 comments
Open

[SR-9183] Memory leak in is type-casting pattern in switch #51674

swift-ci opened this issue Nov 5, 2018 · 3 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 runtime The Swift Runtime

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Nov 5, 2018

Previous ID SR-9183
Radar None
Original Reporter Thomvis (JIRA User)
Type Bug

Attachment: Download

Environment

Xcode 10.0 / Swift 4.2

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

md5: 1cbd33d5cb077ba1afa7b6f8bc6c1436

Issue Description:

The following code seems to leak `toVC`:

public func navigationController(
        _ navigationController: UINavigationController,
        animationControllerFor operation: UINavigationControllerOperation,
        from fromVC: UIViewController,
        to toVC: UIViewController
    ) -> UIViewControllerAnimatedTransitioning? {
        switch (operation, fromVC, toVC) {
        case (.push, _, is ElementwiseAppearTransitionViewController):
            return ElementwiseAppearTransition()
        default:
            return nil
        }
}

I accept that there's a chance this is related to my own code, but since a small change in this code (see attachment) fixed the leak, I felt it was worth a bug report. I haven't been able to find a reduced example yet unfortunately. Let me know if you want me to explore a particular cause or need more input.

@belkadan
Copy link
Contributor

belkadan commented Nov 5, 2018

@mikeash, @jckarter, is this familiar?

@mikeash
Copy link
Contributor

mikeash commented Nov 5, 2018

Not to me. An obvious small example fails to replicate the problem, too.

Thomvis (JIRA User) Are you able to verify that an excess retain happens in this code (for example, using the Allocations instrument)? If so, what's the stack trace?

@swift-ci
Copy link
Collaborator Author

swift-ci commented Nov 5, 2018

Comment by Thomas Visser (JIRA)

Thanks for your responses.

@mikeash Thanks for reminding me. It was the allocations instrument that initially pointed me in the direction of this code. A few observations:

  • I do see two retains and a single release when the function is called with the subject instance as the toVC. When it is called later as as the fromVC (when popping the VC), there is a single retain and release pair.

  • I've attached screenshots of the stacktraces where memory is allocated in the function. Not sure if related. (I could not resize the popover to reveal more info, because Instruments would crash)

  • I've attached the disassembly. It doesn't mean much to me, but perhaps it is of help.

Hope this helps!

vcleak

@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 memory leak bug: Memory leak runtime The Swift Runtime
Projects
None yet
Development

No branches or pull requests

3 participants