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-1310] Referenced object of protocol type does not deallocate if its function throws #43918

Closed
swift-ci opened this issue Apr 25, 2016 · 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

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-1310
Radar None
Original Reporter urosk (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Swift 2.2

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

md5: f2cbcc5a14d3132082ee9fcc898fba52

Issue Description:

Class A implements a protocol -

protocol myProtocol {
func doThings() throws
}

Class B has the following property:
var a : myProtocol = A()

Class A implements the protocol:
func doThings() throws {
throw
}

Object let b = B() calls a's function.
let _ = try? a.doThings()

We then dealloc b, it's deinit method is called, but a's deinit method is never called.

There are three conditions for this to happen.

1.) a needs to be a property of protocol type on another class. If it's created the same way in function scope, a's deinit is called
2.) This happens only if doThings() throws. If it doesn't throw, a's deinit is called.
3.) This happens only if we run the function on a protocol type. If we run the function this way - try (a as! A).doThings(), a's deinit is called.

If you try to check the state of a after b has deinitialized, you can see it has become a "zombie optional".

@belkadan
Copy link
Contributor

Sounds like SR-919. Does this reproduce in the Xcode 7.3.1 GM?

@swift-ci
Copy link
Collaborator Author

Comment by Uros Katic (JIRA)

7.3.1. doesn't seem to fix it. I'm attaching a swift file to help test this. main.swift

@belkadan
Copy link
Contributor

Okay, looks like the fix for this one didn't make it into 7.3.1, but it is in master, which means it'll be in Swift 3.0. Thanks for reporting it!

@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

2 participants