本文介绍了做的第一MapActivity实例总是漏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

而在我们的应用研究记忆问题,事实证明,如果应用程序活动是MapActivity,它的第一个实例不会被最终确定。导致其他内存泄漏等传递到的setContentView的看法。

While investigating memory issues in our application, it turns out that if the application Activity is a MapActivity, the first instance of it won't be finalized. Leading to other memory leak such as the view passed to setContentView.

有没有人注意过吗?

下面是测试code显示出MainActivity:1没有最终确定,而它如果MainActivity自Activity继承

Here is the testing code showing that "MainActivity : 1" is not finalized whereas it is if MainActivity inherits from Activity.

要测试,需要改变设备或模拟器的方向很多次了。

To test, one needs to change device or emulator orientation many times.


import com.google.android.maps.MapActivity;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class MainActivity extends MapActivity {
  private static final String  defaultTag          = "MA";

  private static final boolean isDebugModeActivate = true;
  private static final boolean isClassTagDisplayed = false;
  private static final boolean isWebModeActivate   = false;

  static public void d(Object thiso, String message)
  {
      String tag = defaultTag + (isClassTagDisplayed == true ? "_" + thiso.getClass().getSimpleName() : "");
      message = (isClassTagDisplayed == false ? thiso.getClass().getSimpleName() + " : " : "") + message;
      Log.d(tag, message);
  }

  public MainActivity()
  {
    counter++;
    uid++;
    id = uid;
    d(this, id + " tst constructor (" + counter + ")");
  }
  private static int counter = 0;
  private static int uid = 0;
  private final int id;

  protected void finalize() throws Throwable
  {
    counter--;
    d(this, id + " tst finalize (" +counter + ") ");
    super.finalize();
  }

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

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

感谢您,大卫

推荐答案

也许你应该NickT <一换文href="http://stackoverflow.com/questions/5111139/why-does-my-$c$c-leak-when-switching-activities/5111261#5111261">here

Perhaps you should exchange notes with NickT here

这篇关于做的第一MapActivity实例总是漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 18:50