Skip to content

Commit

Permalink
fix memory leak
Browse files Browse the repository at this point in the history
Summary:
Signed-off-by: yk3372 <[email protected]>

What existing problem does the pull request solve?

ViewManagersPropertyCache, ViewManagerPropertyUpdater static field not release when ReactInstanceManager called destroy.

I use this url to integrate RN:
[http://facebook.github.io/react-native/docs/integration-with-existing-apps.html](http://facebook.github.io/react-native/docs/integration-with-existing-apps.html)
and in Activity's onDestroy function add the follow code to release RN:
```java
mReactInstanceManager.destroy();
mReactInstanceManager = null;
```
and then when I exit activity, find the static field not release.
the follow is screen shot:
before:
![2017-05-23 17 41 16](https://cloud.githubusercontent.com/assets/1514899/26350318/53ea250c-3fe5-11e7-8eda-a0dcc20ba4f6.jpg)
after:
![2017-05-23 17 38 49](https://cloud.githubusercontent.com/assets/1514899/26350329/5e5b273e-3fe5-11e7-9b0b-a8b0e044abf3.jpg)
Closes #14172

Differential Revision: D5128834

Pulled By: javache

fbshipit-source-id: 657763fa21fd8826b4060f9a17e7f35f0e1e04d3
  • Loading branch information
yk3372 authored and facebook-github-bot committed May 25, 2017
1 parent 7cddaa0 commit 9dc0385
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public void onCatalystInstanceDestroy() {

getReactApplicationContext().unregisterComponentCallbacks(mMemoryTrimCallback);
YogaNodePool.get().clear();
ViewManagerPropertyUpdater.clear();
}

private static Map<String, Object> createConstants(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public interface ShadowNodeSetter<T extends ReactShadowNode> extends Settable {
new HashMap<>();
private static final Map<Class<?>, ShadowNodeSetter<?>> SHADOW_NODE_SETTER_MAP = new HashMap<>();

public static void clear() {
ViewManagersPropertyCache.clear();
VIEW_MANAGER_SETTER_MAP.clear();
SHADOW_NODE_SETTER_MAP.clear();
}

public static <T extends ViewManager, V extends View> void updateProps(
T manager,
V v,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
private static final Map<Class, Map<String, PropSetter>> CLASS_PROPS_CACHE = new HashMap<>();
private static final Map<String, PropSetter> EMPTY_PROPS_MAP = new HashMap<>();

public static void clear() {
CLASS_PROPS_CACHE.clear();
EMPTY_PROPS_MAP.clear();
}

/*package*/ static abstract class PropSetter {

protected final String mPropName;
Expand Down

0 comments on commit 9dc0385

Please sign in to comment.