Avoid memory leak in RCTWebSocketModule

Summary: Though this module is dev-only, if not connected to the packager it will collect websockets forever. Some estimate it'll take up 200MB after like 20 minutes.

Reviewed By: shergin

Differential Revision: D6464304

fbshipit-source-id: bef1ce967e4c13dd29e3c7ab4228e9c88d02c157
This commit is contained in:
Mehdi Mulani 2017-12-04 09:18:59 -08:00 committed by Facebook Github Bot
parent ad4450ac13
commit 1e1e491246
1 changed files with 2 additions and 0 deletions

View File

@ -163,6 +163,7 @@ RCT_EXPORT_METHOD(close:(nonnull NSNumber *)socketID)
{
NSNumber *socketID = [webSocket reactTag];
_contentHandlers[socketID] = nil;
_sockets[socketID] = nil;
[self sendEventWithName:@"websocketFailed" body:@{
@"message": error.localizedDescription,
@"id": socketID
@ -176,6 +177,7 @@ RCT_EXPORT_METHOD(close:(nonnull NSNumber *)socketID)
{
NSNumber *socketID = [webSocket reactTag];
_contentHandlers[socketID] = nil;
_sockets[socketID] = nil;
[self sendEventWithName:@"websocketClosed" body:@{
@"code": @(code),
@"reason": RCTNullIfNil(reason),