Does the first MapActivity instance always leak?

删除回忆录丶 提交于 2019-12-05 01:40:43

问题


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.

Does anyone notice that before?

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;
    }
}

Thank you, David


回答1:


Perhaps you should exchange notes with NickT here



来源:https://stackoverflow.com/questions/5111022/does-the-first-mapactivity-instance-always-leak

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!