Skip to content

Commit

Permalink
Network invalidate handlers to cleanup in turbo module mode (#41775)
Browse files Browse the repository at this point in the history
Summary:
We should do some cleanup for handlers in Networking to fix some memory leaks.Ex.  `RCTHTTPRequestHandler` hander, `session` retains the handler which leads to leaks.
https://github.com/facebook/react-native/blob/385473522cbc525aad08500f5a752dea734c14c3/packages/react-native/Libraries/Network/RCTHTTPRequestHandler.mm#L97

## Changelog:

[IOS] [FIXED] - Network invalidate handlers  to cleanup in turbo module mode

Pull Request resolved: #41775

Test Plan: Network handlers clean up after invalidating.

Reviewed By: NickGerleman

Differential Revision: D51846962

Pulled By: dmytrorykun

fbshipit-source-id: 17a2875903cda187f2e3ecea46e8f7f3e10d5264
  • Loading branch information
zhongwuzw authored and facebook-github-bot committed Dec 12, 2023
1 parent 4187a8c commit 44d6e43
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/react-native/Libraries/Network/RCTNetworking.mm
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ - (void)invalidate
[_tasksByRequestID[requestID] cancel];
}
[_tasksByRequestID removeAllObjects];
for (id<RCTURLRequestHandler> handler in _handlers) {
if ([handler conformsToProtocol:@protocol(RCTInvalidating)]) {
[(id<RCTInvalidating>)handler invalidate];
}
}
_handlers = nil;
_requestHandlers = nil;
_responseHandlers = nil;
Expand Down

0 comments on commit 44d6e43

Please sign in to comment.