SwiftWebSocket icon indicating copy to clipboard operation
SwiftWebSocket copied to clipboard

Proper way to close/destroy/deallocate WebSocket

Open utdrmac opened this issue 9 years ago • 6 comments

Hello, I'm using this class inside another object that I'm instantiating. When I attempt to destroy my object, the deinit() is never called. If I do not create the WebSocket(), I can see deinit() is properly called. I'm calling ws.close() but I don't think that's enough to clear out/free all the objects associated with WebSocket(). I also cannot set ws = nil (I thought that would do it)

What is the proper method of deallocating WebSocket?

utdrmac avatar Dec 14 '16 19:12 utdrmac

I think the problem can come from the delegate property which is a default one and so strong https://github.com/tidwall/SwiftWebSocket/blob/master/Source/WebSocket.swift#L1809-L1811 The property should be weak tagged to my mind.

gsempe avatar Dec 23 '16 20:12 gsempe

@utdrmac Is the container class you use an obj-c one?

gsempe avatar Dec 23 '16 21:12 gsempe

@gsempe I'm all Swift 3.0. Latest XCode as of Dec 24th 2016.

utdrmac avatar Dec 24 '16 14:12 utdrmac

Facing the same prob. @utdrmac How did you move forward with this?

GoNinja avatar May 21 '17 16:05 GoNinja

@GoNinja Unfortunately I didn't. I abandoned the project I was working on that used this library.

utdrmac avatar May 21 '17 17:05 utdrmac

BTW @utdrmac I found a solution that worked for me.

Just made the socket reference an optional, and in my viewcontroller on willdisappear I manually closed the connection and set it to nil

GoNinja avatar May 22 '17 17:05 GoNinja