Android谷歌地图MapController泄漏内存

时间:2012-03-07 09:02:08

标签: android memory-leaks map

使用谷歌地图安卓时,我的内存泄漏严重。 我特别注意到使用mapController.animateTo时会注意到它。查看示例代码:从阿姆斯特丹开始我通过增加latlng向南朝意大利方向前进,但是在3分钟内,堆大于超过20Mb,#object达到68000或更高,应用程序崩溃。有谁知道原因是什么或有解决方法?

    public class MapsLeakActivity extends MapActivity 
    {
        MapView       mapView       = null;
        MapController mapController = null;
        Location      mLoc          = new Location("");
        GeoPoint      mGP           = null;

        @Override
        protected void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);

            setContentView(R.layout.mapsleak);

            mapView = (MapView) findViewById(R.id.mapviewml);

            mapView.setKeepScreenOn(true);
            mapView.setSatellite(false);
            mapView.setBuiltInZoomControls(false);

            mapController = mapView.getController();
            mapController.setZoom(17);

            // We start in Amsterdam
            mLoc.setLatitude(52.29);
            mLoc.setLongitude(5.09);

            Timer     timer  = new Timer();
            TimerTask moveOn = new TimerTask()
            {
                @Override
                public void run()
                {
                    // Italy here we come ;) (if it wasn't for the memoryleaking)
                    mLoc.setLatitude(mLoc.getLatitude() - 0.05);
                    mLoc.setLongitude(mLoc.getLongitude() + 0.05);
                    mGP = new GeoPoint((int)(mLoc.getLatitude() * 1E6), (int) (mLoc.getLongitude() * 1E6));
                    mapController.animateTo(mGP);

                 // System.gc();  Tried this already; does not help!
               }            
            };
            timer.schedule(moveOn , 1000, 2000);
        }

        @Override
        protected void onResume()
        {
            super.onResume();
        }

        @Override
        protected void onPause()
        {
            super.onPause();
        }

        @Override
        protected void onDestroy()
        {
            super.onDestroy();
        }

        @Override
        protected boolean isRouteDisplayed()
        {
            return (true);
        }
    }

0 个答案:

没有答案