Socket.IO-Client-Swift icon indicating copy to clipboard operation
Socket.IO-Client-Swift copied to clipboard

Attempting to retain a deallocated object inside connect

Open ysholqamy opened this issue 10 years ago • 3 comments

Hello, I get an error when I try to deallocate the socket, the case is the following: sometimes I need to change the connect params of the socket so I deallocate the old socket and init a new one, the problem is if this is done just after connecting the old socket I get an error inside connect method saying attempting to retain a deallocated object in the last line inside the second dispatch_async. So any idea how I could fix that? Also, what is the best practice for re initializing a socket?

ysholqamy avatar Oct 13 '15 09:10 ysholqamy

Are you connecting with a timeout?

nuclearace avatar Oct 13 '15 15:10 nuclearace

No

ysholqamy avatar Oct 13 '15 17:10 ysholqamy

I think I found the problem, engine.createWebSocket() calls webSocket.connect() and releases the created web socket , which will result in a race condition because the webSocket can still be accessed from within the async connect. I have no idea how to fix, I believe the only way is to make the closure in the async operation a strong retainer for the web socket instead of weak, still this would be a bad solution because it is generally a bad practice to strong reference an object from within a background operation.

ysholqamy avatar Oct 13 '15 19:10 ysholqamy