WowzaMediaSystems / gocoder-sdk-samples-ios

Sample apps for iOS that demonstrate the capabilities of the Wowza GoCoder™ SDK.
https://www.wowza.com/products/gocoder/sdk
Other
37 stars 14 forks source link

Retain cycle when starting streaming #12

Open a-voronov opened 6 years ago

a-voronov commented 6 years ago

WowzaSDK seems to retain reference to WOWZStatusCallback when calling WowzaGoCoder.startStreaming(_:).

Following tutorials, I can pass self as a callback, but once I do, instance of my class isn't released as I'm keeping reference to WowzaSDK instance..

class Test: NSObject, WOWZStatusCallback {
    let goCoder: WowzaGoCoder.sharedInstance()!

    func stream() {
        goCoder.startStreaming(self) // here self is retained and never released
    }
}

reproduces in v1.5.1

a-voronov commented 6 years ago

quick fix solution ¯\(ツ)

class Test: NSObject, WOWZStatusCallback {
    let goCoder: WowzaGoCoder.sharedInstance()!

    func stream() {
        goCoder.startStreaming(WOWZStatusCallbackProxy(self)) // now everything's fine
    }
}

class WOWZStatusCallbackProxy: NSObject, WOWZStatusCallback {
    private weak var forwardee: WOWZStatusCallback?

    init(forwardee: WOWZStatusCallback?) {
        self.forwardee = forwardee
        super.init()
    }

    func onWOWZStatus(_ status: WOWZStatus!) {
        forwardee?.onWOWZStatus(status)
    }

    func onWOWZEvent(_ status: WOWZStatus!) {
        forwardee?.onWOWZEvent?(status)
    }

    func onWOWZError(_ status: WOWZStatus!) {
        forwardee?.onWOWZError(status)
    }
}
ravigangwar1991 commented 5 years ago

I'm facing the same problem my app is hanged after calling start streaming.i also tried which code is given.