mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-05-25 03:53:31 +00:00
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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user