zwopple / PocketSocket

Objective-C websocket library for building things that work in realtime on iOS and OS X.
Other
414 stars 129 forks source link

Retain cycle in PSWebSocketServer? #24

Closed paulshapiro closed 8 years ago

paulshapiro commented 9 years ago

Hello there,

First, thanks for the fantastic library.

I just found out that an NSAssert in a block somewhere in my application was causing a retain cycle. I was like, "huh?", so I checked out the definition of NSAssert, and sure enough, it references 'self':

#define NSAssert(condition, desc, ...) \
    do { \
__PRAGMA_PUSH_NO_EXTRA_ARG_WARNINGS \
if (!(condition)) { \
    [[NSAssertionHandler currentHandler] handleFailureInMethod:_cmd \
object:self file:[NSString stringWithUTF8String:__FILE__] \
    lineNumber:__LINE__ description:(desc), ##__VA_ARGS__]; \
} \
        __PRAGMA_POP_NO_EXTRA_ARG_WARNINGS \
    } while(0)
#endif

Anyway, I start searching through the application codebase, and, having included the source of PocketSocket directly in the project, I happened upon an NSAssert within a block within PSWebSocketServer around line 518. I thought you might want to know. Theoretically, it could be causing you to have to release PSWebSocketServer one too many times in order to get apparent proper dealloc behavior.

However, just a heads up, I have not confirmed that this is indeed happening or causing problems in PocketSocket.

Thanks, Paul

robertjpayne commented 8 years ago

@paulshapiro I'm not sure this is actually causing a retain cycle, because while the block does strongly hold onto "self" because of the assert the block is not retained by self once it finishes execution.