From 1e1e49124678f447d980bb22891d25db60fa83b3 Mon Sep 17 00:00:00 2001 From: Mehdi Mulani Date: Mon, 4 Dec 2017 09:18:59 -0800 Subject: [PATCH] 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 --- Libraries/WebSocket/RCTWebSocketModule.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Libraries/WebSocket/RCTWebSocketModule.m b/Libraries/WebSocket/RCTWebSocketModule.m index 6ccf3f495dca73..1feb4b97a524ee 100644 --- a/Libraries/WebSocket/RCTWebSocketModule.m +++ b/Libraries/WebSocket/RCTWebSocketModule.m @@ -163,6 +163,7 @@ - (void)webSocket:(RCTSRWebSocket *)webSocket didFailWithError:(NSError *)error { NSNumber *socketID = [webSocket reactTag]; _contentHandlers[socketID] = nil; + _sockets[socketID] = nil; [self sendEventWithName:@"websocketFailed" body:@{ @"message": error.localizedDescription, @"id": socketID @@ -176,6 +177,7 @@ - (void)webSocket:(RCTSRWebSocket *)webSocket { NSNumber *socketID = [webSocket reactTag]; _contentHandlers[socketID] = nil; + _sockets[socketID] = nil; [self sendEventWithName:@"websocketClosed" body:@{ @"code": @(code), @"reason": RCTNullIfNil(reason),