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

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

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

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


Copy link

@swift-ci swift-ci commented Nov 5, 2018

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

Attachment: Download


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()
            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.

Copy link

@belkadan belkadan commented Nov 5, 2018

@mikeash, @jckarter, is this familiar?

Copy link

@mikeash 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?

Copy link
Collaborator Author

@swift-ci 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!


@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
None yet

No branches or pull requests

3 participants