Fix memory leak: remove references to SvgViews in onDetachedFromWindow

It looks like onDropViewInstance does not get called when the entire react
instance is shut down from the native side. To gaurantee that we do not
leak memory, we need to remove the reference to the view in onDetachedFromWindow().
This commit is contained in:
Seth Madison
2018-07-18 16:06:36 -07:00
parent b30823183e
commit 149259de64
2 changed files with 12 additions and 7 deletions
@@ -72,6 +72,12 @@ public class SvgView extends ViewGroup {
SvgViewManager.setSvgView(this);
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
SvgViewManager.dropSvgView(this);
}
public void setBitmap(Bitmap bitmap) {
if (mBitmap != null) {
mBitmap.recycle();
@@ -51,6 +51,12 @@ class SvgViewManager extends ViewGroupManager<SvgView> {
mTagToSvgView.put(svg.getId(), svg);
}
static void dropSvgView(SvgView view) {
int tag = view.getId();
mTagToShadowNode.remove(tag);
mTagToSvgView.remove(tag);
}
@SuppressWarnings("unused")
static @Nullable SvgView getSvgViewByTag(int tag) {
return mTagToSvgView.get(tag);
@@ -77,13 +83,6 @@ class SvgViewManager extends ViewGroupManager<SvgView> {
return node;
}
@Override
public void onDropViewInstance(SvgView view) {
int tag = view.getId();
mTagToShadowNode.remove(tag);
mTagToSvgView.remove(tag);
}
@Override
protected SvgView createViewInstance(ThemedReactContext reactContext) {
return new SvgView(reactContext);