Merge "Only populate stack when StrictMode will use it." into ics-mr1

This commit is contained in:
Jeff Sharkey
2011-10-26 15:37:34 -07:00
committed by Android (Google) Code Review
2 changed files with 13 additions and 5 deletions

View File

@@ -49,7 +49,7 @@ import android.util.Log;
/** the following are for debugging purposes */
private String mSqlStmt = null;
private Throwable mStackTrace = null;
private final Throwable mStackTrace;
/** when in cache and is in use, this member is set */
private boolean mInUse = false;
@@ -59,7 +59,11 @@ import android.util.Log;
db.verifyLockOwner();
mDatabase = db;
mSqlStmt = sql;
mStackTrace = new DatabaseObjectNotClosedException().fillInStackTrace();
if (StrictMode.vmSqliteObjectLeaksEnabled()) {
mStackTrace = new DatabaseObjectNotClosedException().fillInStackTrace();
} else {
mStackTrace = null;
}
nHandle = db.mNativeHandle;
native_compile(sql);
}
@@ -112,7 +116,7 @@ import android.util.Log;
// but if the database itself is not closed and is GC'ed, then
// all sub-objects attached to the database could end up getting GC'ed too.
// in that case, don't print any warning.
if (mInUse && StrictMode.vmSqliteObjectLeaksEnabled()) {
if (mInUse && mStackTrace != null) {
int len = mSqlStmt.length();
StrictMode.onSqliteObjectLeaked(
"Releasing statement in a finalizer. Please ensure " +

View File

@@ -95,7 +95,11 @@ public class SQLiteCursor extends AbstractWindowedCursor {
if (query.mDatabase == null) {
throw new IllegalArgumentException("query.mDatabase cannot be null");
}
mStackTrace = new DatabaseObjectNotClosedException().fillInStackTrace();
if (StrictMode.vmSqliteObjectLeaksEnabled()) {
mStackTrace = new DatabaseObjectNotClosedException().fillInStackTrace();
} else {
mStackTrace = null;
}
mDriver = driver;
mEditTable = editTable;
mColumnNameMap = null;
@@ -319,7 +323,7 @@ public class SQLiteCursor extends AbstractWindowedCursor {
try {
// if the cursor hasn't been closed yet, close it first
if (mWindow != null) {
if (StrictMode.vmSqliteObjectLeaksEnabled()) {
if (mStackTrace != null) {
int len = mQuery.mSql.length();
StrictMode.onSqliteObjectLeaked(
"Finalizing a Cursor that has not been deactivated or closed. " +