Files
react-native/ReactCommon/react/renderer/leakchecker/WeakFamilyRegistry.cpp
T
Samuel Susla 34d189ae09 Introducing Leak Checker
Summary:
Changelog: [internal]

Introducing LeakChecker. A tool that checks if all native components have been cleaned up when surface is stopped.

**Known shortcomings**:
- LeakChecker is only enabled in debug builds and the existence of leaks is logged to console.
- For now, Leak Checker looks at N-1 screen. This is intentional as there is a known limitation of React that doesn't free up all shadow nodes when surface is stopped. Because of this, the use of LeakChecker is not intuitive and I'll work with React team to try to work around this.
- It doesn't help locating the leak, it only informs that leak is present. I'll be looking into ways to help locate the leak.

Reviewed By: JoshuaGross, mdvacca

Differential Revision: D26727461

fbshipit-source-id: 8350190b99f24642f8e15a3c2e1d79cfaa810d3d
2021-03-17 02:57:37 -07:00

38 lines
1.0 KiB
C++

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "WeakFamilyRegistry.h"
namespace facebook {
namespace react {
void WeakFamilyRegistry::add(
ShadowNodeFamily::Shared const &shadowNodeFamily) const {
std::lock_guard<std::mutex> lock(familiesMutex_);
ShadowNodeFamily::Weak weakFamily = shadowNodeFamily;
families_[shadowNodeFamily->getSurfaceId()].push_back(weakFamily);
}
void WeakFamilyRegistry::removeFamiliesWithSurfaceId(
SurfaceId surfaceId) const {
std::lock_guard<std::mutex> lock(familiesMutex_);
families_.erase(surfaceId);
}
WeakFamilyRegistry::WeakFamilies WeakFamilyRegistry::weakFamiliesForSurfaceId(
SurfaceId surfaceId) const {
std::lock_guard<std::mutex> lock(familiesMutex_);
if (families_.find(surfaceId) != families_.end()) {
return families_[surfaceId];
} else {
return {};
}
}
} // namespace react
} // namespace facebook