Comment out the finalize() methods defined on the Activity,
ContextImpl, View and ViewRoot classes. This allows instances of subclasses to be collected without the additional latency of finalization.
This commit is contained in:
@@ -678,17 +678,19 @@ public class Activity extends ContextThemeWrapper
|
||||
private Thread mUiThread;
|
||||
private final Handler mHandler = new Handler();
|
||||
|
||||
// Used for debug only
|
||||
/*
|
||||
public Activity() {
|
||||
++sInstanceCount;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
super.finalize();
|
||||
--sInstanceCount;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
public static long getInstanceCount() {
|
||||
return sInstanceCount;
|
||||
}
|
||||
|
||||
@@ -209,11 +209,14 @@ class ContextImpl extends Context {
|
||||
|
||||
private static final String[] EMPTY_FILE_LIST = {};
|
||||
|
||||
// For debug only
|
||||
/*
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
super.finalize();
|
||||
--sInstanceCount;
|
||||
}
|
||||
*/
|
||||
|
||||
public static long getInstanceCount() {
|
||||
return sInstanceCount;
|
||||
@@ -1446,7 +1449,8 @@ class ContextImpl extends Context {
|
||||
}
|
||||
|
||||
ContextImpl() {
|
||||
++sInstanceCount;
|
||||
// For debug only
|
||||
//++sInstanceCount;
|
||||
mOuterContext = this;
|
||||
}
|
||||
|
||||
|
||||
@@ -1819,7 +1819,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
|
||||
mContext = context;
|
||||
mResources = context != null ? context.getResources() : null;
|
||||
mViewFlags = SOUND_EFFECTS_ENABLED | HAPTIC_FEEDBACK_ENABLED;
|
||||
++sInstanceCount;
|
||||
// Used for debug only
|
||||
//++sInstanceCount;
|
||||
mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
|
||||
}
|
||||
|
||||
@@ -2133,11 +2134,14 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
|
||||
View() {
|
||||
}
|
||||
|
||||
// Used for debug only
|
||||
/*
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
super.finalize();
|
||||
--sInstanceCount;
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
||||
@@ -230,7 +230,8 @@ public final class ViewRoot extends Handler implements ViewParent,
|
||||
lt = new LatencyTimer(100, 1000);
|
||||
}
|
||||
|
||||
++sInstanceCount;
|
||||
// For debug only
|
||||
//++sInstanceCount;
|
||||
|
||||
// Initialize the statics when this class is first instantiated. This is
|
||||
// done here instead of in the static block because Zygote does not
|
||||
@@ -258,11 +259,14 @@ public final class ViewRoot extends Handler implements ViewParent,
|
||||
mDensity = context.getResources().getDisplayMetrics().densityDpi;
|
||||
}
|
||||
|
||||
// For debug only
|
||||
/*
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
super.finalize();
|
||||
--sInstanceCount;
|
||||
}
|
||||
*/
|
||||
|
||||
public static long getInstanceCount() {
|
||||
return sInstanceCount;
|
||||
|
||||
Reference in New Issue
Block a user