chat-health / chat.android

Android app for the CHAT project
GNU General Public License v3.0
2 stars 3 forks source link

SQLite connections are not closed properly #3

Closed mackrauss closed 10 years ago

mackrauss commented 10 years ago

Getting warnings of this kind every now and then: "SQLiteConnectionPool - A SQLiteConnection object for database '/data/data/org.chat.android/databases/chat.db' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed."

At the same time I was delivering services for some of the clients and when looking at services_accessed table it was empty.

Might have to do with #1 and #2 since I have one client several times available. But this might not be related.

mackrauss commented 10 years ago

Looks like we often do

DatabaseHelper dbHelper = new DatabaseHelper(context);

Which generates a lot of database connection.

According to the ORMLite doc http://ormlite.com/javadoc/ormlite-core/doc-files/ormlite_4.html#Use-With-Android we should either inherit from OrmLiteBaseActivity<DatabaseHelper> or use OpenHelperManager

see also: https://github.com/j256/ormlite-examples/blob/master/android/HelloAndroid/src/com/example/helloandroid/HelloAndroid.java and http://ormlite.com/javadoc/ormlite-android/com/j256/ormlite/android/apptools/OpenHelperManager.html

Lot of work ahead :/

mackrauss commented 10 years ago

Replaced all calls of new DatabaseHelper with getHelper() instead. Done with commit 127d8660382ad840c72c82637be284c617934a70