Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 118489f

Browse files
sammy-SCfacebook-github-bot
authored andcommittedMay 21, 2021
Make LeakChecker available on Android
Summary: Changelog: [internal] Extend LeakChecker so it is available on Android (or any other platform as it is completely in C++ now). Reviewed By: JoshuaGross Differential Revision: D28600243 fbshipit-source-id: c77a003e3ffc6171e61c998508c9f34f10bb65ca
1 parent ffab8e3 commit 118489f

File tree

9 files changed

+17
-57
lines changed

9 files changed

+17
-57
lines changed
 

‎React/Base/RCTBridge+Private.h

-2
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,4 @@ RCT_EXTERN void RCTRegisterModule(Class);
146146

147147
- (instancetype)initWithParentBridge:(RCTBridge *)bridge NS_DESIGNATED_INITIALIZER;
148148

149-
- (void)forceGarbageCollection;
150-
151149
@end

‎React/CxxBridge/RCTCxxBridge.mm

-6
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ @interface RCTCxxBridge ()
194194
- (instancetype)initWithParentBridge:(RCTBridge *)bridge;
195195
- (void)partialBatchDidFlush;
196196
- (void)batchDidComplete;
197-
- (void)forceGarbageCollection;
198197

199198
@end
200199

@@ -381,11 +380,6 @@ - (void)_tryAndHandleError:(dispatch_block_t)block
381380
}
382381

383382
- (void)handleMemoryWarning
384-
{
385-
[self forceGarbageCollection];
386-
}
387-
388-
- (void)forceGarbageCollection
389383
{
390384
// We only want to run garbage collector when the loading is finished
391385
// and the instance is valid.

‎React/Fabric/RCTSurfacePresenter.mm

-13
Original file line numberDiff line numberDiff line change
@@ -293,19 +293,6 @@ - (RCTScheduler *)_createScheduler
293293
toolbox.backgroundExecutor = RCTGetBackgroundExecutor();
294294
}
295295

296-
#ifdef REACT_NATIVE_DEBUG
297-
auto optionalBridge = _contextContainer->find<std::shared_ptr<void>>("Bridge");
298-
if (optionalBridge) {
299-
RCTBridge *bridge = unwrapManagedObjectWeakly(optionalBridge.value());
300-
toolbox.garbageCollectionTrigger = [bridge]() {
301-
RCTCxxBridge *batchedBridge = (RCTCxxBridge *)([bridge batchedBridge] ?: bridge);
302-
if ([batchedBridge respondsToSelector:@selector(forceGarbageCollection)]) {
303-
[batchedBridge forceGarbageCollection];
304-
}
305-
};
306-
}
307-
#endif
308-
309296
toolbox.synchronousEventBeatFactory = [runtimeExecutor](EventBeat::SharedOwnerBox const &ownerBox) {
310297
auto runLoopObserver =
311298
std::make_unique<MainRunLoopObserver const>(RunLoopObserver::Activity::BeforeWaiting, ownerBox->owner);

‎ReactCommon/react/renderer/leakchecker/LeakChecker.cpp

+5-8
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,26 @@
88
#include "LeakChecker.h"
99

1010
#include <glog/logging.h>
11+
#include <jsi/instrumentation.h>
1112

1213
namespace facebook {
1314
namespace react {
1415

15-
LeakChecker::LeakChecker(
16-
RuntimeExecutor const &runtimeExecutor,
17-
GarbageCollectionTrigger const &garbageCollectionTrigger)
18-
: runtimeExecutor_(runtimeExecutor),
19-
garbageCollectionTrigger_(garbageCollectionTrigger) {}
16+
LeakChecker::LeakChecker(RuntimeExecutor const &runtimeExecutor)
17+
: runtimeExecutor_(runtimeExecutor) {}
2018

2119
void LeakChecker::uiManagerDidCreateShadowNodeFamily(
2220
ShadowNodeFamily::Shared const &shadowNodeFamily) const {
2321
registry_.add(shadowNodeFamily);
2422
}
2523

2624
void LeakChecker::stopSurface(SurfaceId surfaceId) {
27-
garbageCollectionTrigger_();
28-
2925
if (previouslyStoppedSurface_ > 0) {
3026
// Dispatch the check onto JavaScript thread to make sure all other
3127
// cleanup code has had chance to run.
3228
runtimeExecutor_([previouslySoppedSurface = previouslyStoppedSurface_,
33-
this](jsi::Runtime &) {
29+
this](jsi::Runtime &runtime) {
30+
runtime.instrumentation().collectGarbage("LeakChecker");
3431
// For now check the previous surface because React uses double
3532
// buffering which keeps the surface that was just stopped in
3633
// memory. This is a documented problem in the last point of

‎ReactCommon/react/renderer/leakchecker/LeakChecker.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ using GarbageCollectionTrigger = std::function<void()>;
2020

2121
class LeakChecker final {
2222
public:
23-
LeakChecker(
24-
RuntimeExecutor const &runtimeExecutor,
25-
GarbageCollectionTrigger const &garbageCollectionTrigger);
23+
LeakChecker(RuntimeExecutor const &runtimeExecutor);
2624

2725
void uiManagerDidCreateShadowNodeFamily(
2826
ShadowNodeFamily::Shared const &shadowNodeFamily) const;
@@ -32,7 +30,6 @@ class LeakChecker final {
3230
void checkSurfaceForLeaks(SurfaceId surfaceId) const;
3331

3432
RuntimeExecutor const runtimeExecutor_{};
35-
GarbageCollectionTrigger const garbageCollectionTrigger_{};
3633

3734
WeakFamilyRegistry registry_{};
3835
SurfaceId previouslyStoppedSurface_;

‎ReactCommon/react/renderer/scheduler/Scheduler.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ Scheduler::Scheduler(
4545
std::make_shared<better::optional<EventDispatcher const>>();
4646

4747
auto uiManager = std::make_shared<UIManager>(
48-
runtimeExecutor_,
49-
schedulerToolbox.backgroundExecutor,
50-
schedulerToolbox.garbageCollectionTrigger);
48+
runtimeExecutor_, schedulerToolbox.backgroundExecutor);
5149
auto eventOwnerBox = std::make_shared<EventBeat::OwnerBox>();
5250
eventOwnerBox->owner = eventDispatcher_;
5351

‎ReactCommon/react/renderer/scheduler/SchedulerToolbox.h

-6
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,6 @@ struct SchedulerToolbox final {
6868
*/
6969
BackgroundExecutor backgroundExecutor;
7070

71-
/*
72-
* Triggers garbage collection. Used when checking if all Fabric's HostObjects
73-
* have been properly cleaned up from JavaScript.
74-
*/
75-
GarbageCollectionTrigger garbageCollectionTrigger;
76-
7771
/*
7872
* A list of `UIManagerCommitHook`s that should be registered in `UIManager`.
7973
*/

‎ReactCommon/react/renderer/uimanager/UIManager.cpp

+9-13
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,21 @@
1818

1919
namespace facebook::react {
2020

21-
static std::unique_ptr<LeakChecker> constructLeakChecker(
22-
RuntimeExecutor const &runtimeExecutor,
23-
GarbageCollectionTrigger const &garbageCollectionTrigger) {
24-
if (garbageCollectionTrigger) {
25-
return std::make_unique<LeakChecker>(
26-
runtimeExecutor, garbageCollectionTrigger);
27-
} else {
28-
return {};
29-
}
21+
static std::unique_ptr<LeakChecker> constructLeakCheckerIfNeeded(
22+
RuntimeExecutor const &runtimeExecutor) {
23+
#ifdef REACT_NATIVE_DEBUG
24+
return std::make_unique<LeakChecker>(runtimeExecutor);
25+
#else
26+
return {};
27+
#endif
3028
}
3129

3230
UIManager::UIManager(
3331
RuntimeExecutor const &runtimeExecutor,
34-
BackgroundExecutor const &backgroundExecutor,
35-
GarbageCollectionTrigger const &garbageCollectionTrigger)
32+
BackgroundExecutor const &backgroundExecutor)
3633
: runtimeExecutor_(runtimeExecutor),
3734
backgroundExecutor_(backgroundExecutor),
38-
leakChecker_(
39-
constructLeakChecker(runtimeExecutor, garbageCollectionTrigger)) {}
35+
leakChecker_(constructLeakCheckerIfNeeded(runtimeExecutor)) {}
4036

4137
UIManager::~UIManager() {
4238
LOG(WARNING) << "UIManager::~UIManager() was called (address: " << this

‎ReactCommon/react/renderer/uimanager/UIManager.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ class UIManager final : public ShadowTreeDelegate {
3333
public:
3434
UIManager(
3535
RuntimeExecutor const &runtimeExecutor,
36-
BackgroundExecutor const &backgroundExecutor,
37-
GarbageCollectionTrigger const &garbageCollectionTrigger);
36+
BackgroundExecutor const &backgroundExecutor);
3837

3938
~UIManager();
4039

0 commit comments

Comments
 (0)
Please sign in to comment.