am 6d1ec0d8: dealloc compiled-sql statements before deref\'ing them from SQLiteDatabase obj.
Merge commit '6d1ec0d81cd8ecdd390b31e724bac554bb955a94' into eclair-mr2-plus-aosp * commit '6d1ec0d81cd8ecdd390b31e724bac554bb955a94': dealloc compiled-sql statements before deref'ing them from SQLiteDatabase obj.
This commit is contained in:
@@ -827,6 +827,15 @@ public class SQLiteDatabase extends SQLiteClosable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void closeClosable() {
|
private void closeClosable() {
|
||||||
|
/* deallocate all compiled sql statement objects in compiledQueries cache.
|
||||||
|
* this should be done before de-referencing all {@link SQLiteClosable} objects
|
||||||
|
* from this database object because calling
|
||||||
|
* {@link SQLiteClosable#onAllReferencesReleasedFromContainer()} could cause the database
|
||||||
|
* to be closed. sqlite doesn't let a database close if there are
|
||||||
|
* any unfinalized statements - such as the compiled-sql objects in mCompiledQueries.
|
||||||
|
*/
|
||||||
|
resetCompiledSqlCache();
|
||||||
|
|
||||||
Iterator<Map.Entry<SQLiteClosable, Object>> iter = mPrograms.entrySet().iterator();
|
Iterator<Map.Entry<SQLiteClosable, Object>> iter = mPrograms.entrySet().iterator();
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
Map.Entry<SQLiteClosable, Object> entry = iter.next();
|
Map.Entry<SQLiteClosable, Object> entry = iter.next();
|
||||||
@@ -835,13 +844,6 @@ public class SQLiteDatabase extends SQLiteClosable {
|
|||||||
program.onAllReferencesReleasedFromContainer();
|
program.onAllReferencesReleasedFromContainer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// finalize all compiled sql statement objects in compiledQueries cache
|
|
||||||
synchronized (mCompiledQueries) {
|
|
||||||
for (SQLiteCompiledSql compiledStatement : mCompiledQueries.values()) {
|
|
||||||
compiledStatement.releaseSqlStatement();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1789,7 +1791,9 @@ public class SQLiteDatabase extends SQLiteClosable {
|
|||||||
*/
|
*/
|
||||||
public void setMaxSqlCacheSize(int cacheSize) {
|
public void setMaxSqlCacheSize(int cacheSize) {
|
||||||
synchronized(mCompiledQueries) {
|
synchronized(mCompiledQueries) {
|
||||||
resetCompiledSqlCache();
|
if (mMaxSqlCacheSize > 0) {
|
||||||
|
resetCompiledSqlCache();
|
||||||
|
}
|
||||||
mMaxSqlCacheSize = (cacheSize > MAX_SQL_CACHE_SIZE) ? MAX_SQL_CACHE_SIZE
|
mMaxSqlCacheSize = (cacheSize > MAX_SQL_CACHE_SIZE) ? MAX_SQL_CACHE_SIZE
|
||||||
: (cacheSize < 0) ? 0 : cacheSize;
|
: (cacheSize < 0) ? 0 : cacheSize;
|
||||||
}
|
}
|
||||||
@@ -1800,6 +1804,9 @@ public class SQLiteDatabase extends SQLiteClosable {
|
|||||||
*/
|
*/
|
||||||
public void resetCompiledSqlCache() {
|
public void resetCompiledSqlCache() {
|
||||||
synchronized(mCompiledQueries) {
|
synchronized(mCompiledQueries) {
|
||||||
|
for (SQLiteCompiledSql compiledStatement : mCompiledQueries.values()) {
|
||||||
|
compiledStatement.releaseSqlStatement();
|
||||||
|
}
|
||||||
mCompiledQueries.clear();
|
mCompiledQueries.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1835,7 +1842,7 @@ public class SQLiteDatabase extends SQLiteClosable {
|
|||||||
/* reached max cachesize. before adding new entry, remove an entry from the
|
/* reached max cachesize. before adding new entry, remove an entry from the
|
||||||
* cache. we don't want to wipe out the entire cache because of this:
|
* cache. we don't want to wipe out the entire cache because of this:
|
||||||
* GCing {@link SQLiteCompiledSql} requires call to sqlite3_finalize
|
* GCing {@link SQLiteCompiledSql} requires call to sqlite3_finalize
|
||||||
* JNI method. If entire cache is wiped out, it could be cause a big GC activity
|
* JNI method. If entire cache is wiped out, it could cause a big GC activity
|
||||||
* just because a (rogue) process is using the cache incorrectly.
|
* just because a (rogue) process is using the cache incorrectly.
|
||||||
*/
|
*/
|
||||||
Set<String> keySet = mCompiledQueries.keySet();
|
Set<String> keySet = mCompiledQueries.keySet();
|
||||||
@@ -1844,8 +1851,7 @@ public class SQLiteDatabase extends SQLiteClosable {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
compiledSql = new SQLiteCompiledSql(this, sql);
|
mCompiledQueries.put(sql, compiledStatement);
|
||||||
mCompiledQueries.put(sql, compiledSql);
|
|
||||||
}
|
}
|
||||||
if (SQLiteDebug.DEBUG_SQL_CACHE) {
|
if (SQLiteDebug.DEBUG_SQL_CACHE) {
|
||||||
Log.v(TAG, "|adding_sql_to_cache|" + getPath() + "|" + mCompiledQueries.size() + "|" +
|
Log.v(TAG, "|adding_sql_to_cache|" + getPath() + "|" + mCompiledQueries.size() + "|" +
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ public abstract class SQLiteProgram extends SQLiteClosable {
|
|||||||
* @return a unique identifier for this program
|
* @return a unique identifier for this program
|
||||||
*/
|
*/
|
||||||
public final int getUniqueId() {
|
public final int getUniqueId() {
|
||||||
return compiledSql.nStatement;
|
return (compiledSql != null) ? compiledSql.nStatement : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* package */ String getSqlString() {
|
/* package */ String getSqlString() {
|
||||||
|
|||||||
Reference in New Issue
Block a user