Fix small memory leak and mark more exceptions #177
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixed small memory leak
There is a very small memory leak in the code that was inherited from the Android project as reported here: https://code.google.com/p/android/issues/detail?id=22794
The Android project already fixed this leak when making some other changes in November 2011, in this commit: aosp-mirror/platform_frameworks_base@e5360fb
The first commit in this PR fixes the memory leak by replacing
SQLiteDatabase.ActiveDatabases
withprivate static WeakHashMap<SQLiteDatabase, Object> sActiveDatabases
and cleaning it up inSQLiteDatabase.onAllReferencesReleased()
.Note that in the Android project the reference is not cleaned up in case the
SQLiteDatabase
instance is finalized, while no such distinction is made in my commit. I suspect their reasoning was that it would not be worth while to cleanup a weak reference to aSQLiteDatabase
instance that is known to be going away.Mark some more exceptions in SQLiteDatabase class
I marked some more exceptions that may be thrown, as discussed in #176. I also added some Javadoc comments to public functions where missing.
Small fix to public SQLiteDatabase.yieldIfContended functions
I added a small fix to
SQLiteDatabase.yieldIfContended()
,SQLiteDatabase.yieldIfContendedSafely()
, andSQLiteDatabase.yieldIfContendedSafely(long)
to simply returnfalse
if the database is closed.Testing
I tested the changes in a version of the test suite that repeats 9 times, as described in sqlcipher/sqlcipher-android-tests#8.