-
-
Notifications
You must be signed in to change notification settings - Fork 54
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
How to avoid retain cycles when using OSCServer #56
Comments
In OSCServer.swift, open class OSCServer {
// ...
open var delegate: OSCServerDelegate?
// ...
}
|
Thanks for the speedy response @orchetect - I had this suspicion, nice to have that confirmed! I'm still getting a retain cycle after adding |
There could still be retain cycles elsewhere in SwiftOSC or in your code. That was just the most obvious one I spotted. |
Thanks @orchetect - think i've tried every variation of As a workaround I'm instantiating the I'm sure this is something very obvious to Devin that I just can't see :) |
Don't rule out the possibility that I screwed up somewhere. |
In OSCServer.swift line 44. func run() {
DispatchQueue.global().async{
while true {
let (data,_,_) = self.server.recv(9216)
if let data = data {
if self.running {
let data = Data(data)
self.decodePacket(data)
}
}
}
}
} Probably shouldn't be |
I don't have time to dig into this right now. |
Wow. That was some bad programming. |
Awesome, thanks for the quick response Devin - I'll test this and make a PR if it works |
It might not completely solve the issue. But there are definitely issues with that block. |
Also be aware that I'd start by adding |
Maybe I should just pitch @orchetect 's OSC library. https://github.com/orchetect/OSCKit He doesn't include the network layer so it's not plug and play but if you're good with that stuff it should be pretty easy. I know he's done some pretty extensive testing and uses it daily. |
Also, If you check out the dev branch, I was working on using a different Swift Network framework. Maybe try giving that a spin. Full disclosure it's been a while and I'm not sure how well it works. |
Cheers, had a quick look - couldn’t see exactly where the network framework changed, i’ll keep an eye on the dev branch if you become active on there again :)
… On 28 Jan 2021, at 18:37, Devin Roth ***@***.***> wrote:
Also, If you check out the dev branch, I was working on using a different Swift Network framework. Maybe try giving that a spin. Full disclosure it's been a while and I'm not sure how well it works.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Pretty much the entire OSCServer is completely different. |
Hi Devin,
Swift isn't my main language, I'm hoping you could make this clearer for me.
I'm instantiating an OSCServer inside a VC, which I only need while I'm inside that VC. I want to close that connection and deallocate the server when I leave the VC and return to the parent VC.
By making the
server.delegate = self
I cause a retain cycle even if I try settingserver.delegate = nil
inviewWilDisappear()
I've tried declaring my server as
weak
andunowned
What am I missing?
The text was updated successfully, but these errors were encountered: