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-15120] Using Threads in Swift causes memory leak #3949

Closed
swift-ci opened this issue Aug 26, 2021 · 2 comments
Closed

[SR-15120] Using Threads in Swift causes memory leak #3949

swift-ci opened this issue Aug 26, 2021 · 2 comments

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-15120
Radar None
Original Reporter grill2010 (JIRA User)
Type Bug
Status Closed
Resolution Invalid

Attachment: Download

Environment

I'm using

XCode 12.5.1

Swift 5.5

Minimum iOS version

13.0

The app is built for iPhone and iPad

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee None
Priority Medium

md5: 54829ec4c92d275e0feacca6ee17bd9b

Issue Description:

I'm creating a Thread in my ViewModel in Swift like this

import Foundation

class TestViewViewModel: ObservableObject {
    
    private var testThread: TestThread?
    
    public func initViewModel() {
        testThread = TestThread.init()
    }
    
    public func deinitViewModel() {
        testThread?.cancel()
        testThread = nil
    }
    
    
    /*+++++++++++++++*/
    /*+ Test thread +*/
    /*+++++++++++++++*/

    private class TestThread: Thread {

        override init(){
            print("Init RenderThread")
        }
        
        deinit {
            print("deinit RenderThread")
        }

        override func main() {
            
        }
    }
}

I'm not even starting the thread but even after calling deinitViewModel some stuff of the Thread got leaked according to the XCode memory profiler (look at the attached screenshot). It seems it's the threadDictionary but I'm not sure.

@typesanitizer
Copy link

Could you file a bug report for this through feedbackassistant.apple.com ? As far as I can tell, this is specific to the Foundation framework available in the SDK shipped with Xcode, not swift-corelibs-foundation which is available on GitHub.

@swift-ci
Copy link
Contributor Author

Comment by Florian Grill (JIRA)

theindigamer (JIRA User) ah okay. Sure will do

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants