Memory leak for Android Google Maps API v2

前端 未结 2 1666
-上瘾入骨i
-上瘾入骨i 2021-01-16 10:20

I\'m struggling with a memory leak issue at Google Maps Android API v2. The heap usage increases by about 85KB every time my view becomes visible again after:

相关标签:
2条回答
  • 2021-01-16 10:37

    This might be related to this open issue in the Maps API:

    Issue 4766 - Bug: Android Maps API v2 leaks huge amounts of memory

    Use DDMS' "Dump HPROF" tool to dump a hprof file, convert it with hprof-conv and use MAT to examine the leak. If it's in Google Maps API, please post an apk (or better simple test code) to the open issue and include the hprof file.

    If it is the same bug I am experiencing, it might only happen on Android 2.x, please check that too.

    0 讨论(0)
  • 2021-01-16 10:56

    I tried to use System.gc() and map.clear() before the map is initialized.

      @Override
    public void onActivityCreated (Bundle savedInstanceState){
        super.onActivityCreated(savedInstanceState);
    
        if (GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity()) == ConnectionResult.SUCCESS) {
            System.gc();
    getMap().clear();
    setupmap();
    
    
        }
    }
     @Override
    public void onLowMemory() {
      super.onLowMemory();
    System.gc();
    }
    
    0 讨论(0)
提交回复
热议问题