Drop CSSNode pool on low memory when app is backgrounded
Summary: Depends on D4189532 Drops the CSSNodePool when memory gets low. Reviewed By: emilsjolander Differential Revision: D4190264 fbshipit-source-id: 94cd36d877372e0d6ebdd989661af74bde41486d
This commit is contained in:
parent
bd8745b1fd
commit
48bb3648c5
|
@ -11,10 +11,13 @@ package com.facebook.react.uimanager;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import android.content.ComponentCallbacks2;
|
||||||
|
import android.content.res.Configuration;
|
||||||
|
|
||||||
import com.facebook.common.logging.FLog;
|
import com.facebook.common.logging.FLog;
|
||||||
import com.facebook.react.animation.Animation;
|
import com.facebook.react.animation.Animation;
|
||||||
import com.facebook.react.bridge.Callback;
|
import com.facebook.react.bridge.Callback;
|
||||||
|
@ -78,6 +81,7 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
|
||||||
private final EventDispatcher mEventDispatcher;
|
private final EventDispatcher mEventDispatcher;
|
||||||
private final Map<String, Object> mModuleConstants;
|
private final Map<String, Object> mModuleConstants;
|
||||||
private final UIImplementation mUIImplementation;
|
private final UIImplementation mUIImplementation;
|
||||||
|
private final MemoryTrimCallback mMemoryTrimCallback = new MemoryTrimCallback();
|
||||||
|
|
||||||
private int mNextRootViewTag = 1;
|
private int mNextRootViewTag = 1;
|
||||||
private int mBatchId = 0;
|
private int mBatchId = 0;
|
||||||
|
@ -114,6 +118,11 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
|
||||||
return mModuleConstants;
|
return mModuleConstants;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize() {
|
||||||
|
getReactApplicationContext().registerComponentCallbacks(mMemoryTrimCallback);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onHostResume() {
|
public void onHostResume() {
|
||||||
mUIImplementation.onHostResume();
|
mUIImplementation.onHostResume();
|
||||||
|
@ -133,6 +142,9 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
|
||||||
public void onCatalystInstanceDestroy() {
|
public void onCatalystInstanceDestroy() {
|
||||||
super.onCatalystInstanceDestroy();
|
super.onCatalystInstanceDestroy();
|
||||||
mEventDispatcher.onCatalystInstanceDestroyed();
|
mEventDispatcher.onCatalystInstanceDestroyed();
|
||||||
|
|
||||||
|
getReactApplicationContext().unregisterComponentCallbacks(mMemoryTrimCallback);
|
||||||
|
CSSNodePool.get().clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Map<String, Object> createConstants(List<ViewManager> viewManagerList) {
|
private static Map<String, Object> createConstants(List<ViewManager> viewManagerList) {
|
||||||
|
@ -549,4 +561,25 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
|
||||||
public int resolveRootTagFromReactTag(int reactTag) {
|
public int resolveRootTagFromReactTag(int reactTag) {
|
||||||
return mUIImplementation.resolveRootTagFromReactTag(reactTag);
|
return mUIImplementation.resolveRootTagFromReactTag(reactTag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Listener that drops the CSSNode pool on low memory when the app is backgrounded.
|
||||||
|
*/
|
||||||
|
private class MemoryTrimCallback implements ComponentCallbacks2 {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTrimMemory(int level) {
|
||||||
|
if (level >= TRIM_MEMORY_MODERATE) {
|
||||||
|
CSSNodePool.get().clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onConfigurationChanged(Configuration newConfig) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLowMemory() {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue