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-4133] Memory leak when creating instance using generic type from Objective-C protocol #46716

Closed
swift-ci opened this issue Mar 2, 2017 · 4 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

swift-ci commented Mar 2, 2017

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

Attachment: Download

Environment

Xcode 8.2.1, with Swift 3.0.2

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

md5: 45c24b5da431622358b7e4784d1e8383

duplicates:

  • SR-3935 Initializing from @objc protocol with Protocol.Type causes a memory leak

Issue Description:

We have an Objective-C protocol which has an initializer method, and a Swift generic function with that type, creating instance of that generic type using the initializer will cause the created instance being leaked. Full demo project is attached.

// Mode.h
@protocol ObjCInitProtocol <NSObject>
- (instancetype)initWithValue:(NSInteger)value;
@end

// main.swift
func testObjC<T: ObjCInitProtocol>() -> T? {
    weak var object: T?
    do {
        object = T(value: 10) // This instance will be leaked.
    }
    return object
}
@belkadan
Copy link
Contributor

belkadan commented Mar 2, 2017

@slavapestov, did you have something like this?

@belkadan
Copy link
Contributor

belkadan commented Mar 2, 2017

Tony, your project's missing a few files. Maybe they were in another directory when you zipped it up?

@swift-ci
Copy link
Collaborator Author

swift-ci commented Mar 5, 2017

Comment by Tony Li (JIRA)

@belkadan Sorry, fixed demo project is uploaded.

@slavapestov
Copy link
Member

This was fixed in Xcode 9.3.

@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