android MapView always causes an OutOfMemoryError in nested elements

后端 未结 7 1473
我在风中等你
我在风中等你 2020-12-03 12:55

I am trying to create a MapView (currently without any overlays) inside some nested elements. It is basically something like ScrollView -> RelativeLayout -> Rela

7条回答
  •  情话喂你
    2020-12-03 13:07

    Take a look at the following thread:

    Issue 2181:Memory leak in system when using MapView

    Seems like this is something internal in MapActivity. The thread is alive for over two years now and it was not reported as fixed...

    Edit: tried the solution described there and it led me to a similar solution:

    try {
            Field mConfigField = MapActivity.class.getDeclaredField("mConfig");
            mConfigField.setAccessible(true);
    
            Object mConfig = mConfigField.get(this);
            if (null != mConfig)
            {
                Field mConfigContextField = mConfig.getClass().getDeclaredField("context");
                mConfigContextField.setAccessible(true);
    
                mConfigContextField.set(mConfig, null);
    
                mConfigField.set(this, null);
            }
    
        } catch (Exception ex) {
            // Do error handling
        }
    

提交回复
热议问题