Skip to content

Using takeRetainedValue is a bad idea and leads to crashes (iOS 15) #41

@houmie

Description

@houmie

I start getting exception errors on the second line, even though I'm passing clearly "facebook.com" to it.

let cfhost = CFHostCreateWithName(nil, host as CFString).takeRetainedValue()
let status = CFHostStartInfoResolution(cfhost, .addresses, &streamError)

takeRetainedValue is saying that I'm responsible for keeping that string variable in scope. But that value could be getting deallocated while it's still being used, when the app goes in background mode for example.

It could be nil by the time it gets to line two. The solution could be maybe to hold onto it as a class variable instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions