Skip to content

Commit

Permalink
Merge pull request #28 from blueshift-labs/memory_leak_fixes
Browse files Browse the repository at this point in the history
Memory Leak Optimization (for db)
  • Loading branch information
rahulrvp committed Nov 4, 2016
2 parents 7c4ab42 + 4c2088b commit 1719844
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 33 deletions.
4 changes: 2 additions & 2 deletions android-sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ext {
siteUrl = 'https://getblueshift.com/'
gitUrl = 'https://github.com/blueshift-labs/Blueshift-Android-SDK.git'

libraryVersion = '0.6.1'
libraryVersion = '0.6.2'

developerId = 'nipun'
developerName = 'Nipun Bhatia'
Expand Down Expand Up @@ -133,7 +133,7 @@ if (project.hasProperty("android")) { // Android libraries
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
// todo: remove below line when fixes are applied for excluding external aars for javadoc.
failOnError = false;
// failOnError = false;
}
} else { // Java libraries
task sourcesJar(type: Jar, dependsOn: classes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,17 @@ public ArrayList<T> findAll() {
if (db != null) {
Cursor cursor = db.query(getTableName(), null, null, null, null, null, null);
if (cursor != null) {
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
result.add(loadObject(cursor));
cursor.moveToNext();
if (cursor.moveToFirst()) {
while (!cursor.isAfterLast()) {
result.add(loadObject(cursor));
cursor.moveToNext();
}
}

cursor.close();
}

db.close();
}
}

Expand All @@ -213,11 +218,11 @@ public ArrayList<T> findWithLimit(int limit) {
if (db != null) {
Cursor cursor = db.rawQuery("SELECT * FROM " + getTableName() + " LIMIT " + limit, null);
if (cursor != null) {
cursor.moveToFirst();

while (!cursor.isAfterLast()) {
result.add(loadObject(cursor));
cursor.moveToNext();
if (cursor.moveToFirst()) {
while (!cursor.isAfterLast()) {
result.add(loadObject(cursor));
cursor.moveToNext();
}
}

cursor.close();
Expand All @@ -239,9 +244,13 @@ public T findByField(String fieldName, String value) {
if (db != null) {
Cursor cursor = db.query(getTableName(), null, fieldName + "='" + value + "'", null, null, null, null);
if (cursor != null) {
cursor.moveToFirst();
object = loadObject(cursor);
if (cursor.moveToFirst()) {
object = loadObject(cursor);
}

cursor.close();
}

db.close();
}
}
Expand All @@ -258,9 +267,13 @@ public T findByField(String fieldName, long value) {
if (db != null) {
Cursor cursor = db.query(getTableName(), null, fieldName + "=" + value, null, null, null, null);
if (cursor != null) {
cursor.moveToFirst();
object = loadObject(cursor);
if (cursor.moveToFirst()) {
object = loadObject(cursor);
}

cursor.close();
}

db.close();
}
}
Expand All @@ -277,9 +290,13 @@ public T findRandomByField(String fieldName, long value) {
if (db != null) {
Cursor cursor = db.query(getTableName(), null, fieldName + "=" + value, null, null, null, "RANDOM()");
if (cursor != null) {
cursor.moveToFirst();
object = loadObject(cursor);
if (cursor.moveToFirst()) {
object = loadObject(cursor);
}

cursor.close();
}

db.close();
}
}
Expand All @@ -295,12 +312,17 @@ public ArrayList<T> findAllByField(String fieldName, String value) {
if (db != null) {
Cursor cursor = db.query(getTableName(), null, fieldName + "='" + value + "'", null, null, null, null);
if (cursor != null) {
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
result.add(loadObject(cursor));
cursor.moveToNext();
if (cursor.moveToFirst()) {
while (!cursor.isAfterLast()) {
result.add(loadObject(cursor));
cursor.moveToNext();
}
}

cursor.close();
}

db.close();
}
}

Expand All @@ -320,12 +342,17 @@ public ArrayList<T> findAllByField(String[] fieldNames, String[] values) {

Cursor cursor = db.query(getTableName(), null, selection, values, null, null, null);
if (cursor != null) {
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
result.add(loadObject(cursor));
cursor.moveToNext();
if (cursor.moveToFirst()) {
while (!cursor.isAfterLast()) {
result.add(loadObject(cursor));
cursor.moveToNext();
}
}

cursor.close();
}

db.close();
}
}

Expand All @@ -346,12 +373,17 @@ public ArrayList<T> findAllByField(String[] fieldNames, String[] values, int pag

Cursor cursor = db.query(getTableName(), null, selection, values, null, null, order, String.valueOf(100 * pageNo));
if (cursor != null) {
cursor.moveToPosition(100 * (pageNo - 1));
while (!cursor.isAfterLast()) {
result.add(loadObject(cursor));
cursor.moveToNext();
if (cursor.moveToPosition(100 * (pageNo - 1))) {
while (!cursor.isAfterLast()) {
result.add(loadObject(cursor));
cursor.moveToNext();
}
}

cursor.close();
}

db.close();
}
}

Expand All @@ -372,12 +404,17 @@ public ArrayList<T> findAllByField(String[] fieldNames, String[] values, int pag

Cursor cursor = db.query(getTableName(), null, selection, values, null, null, order, String.valueOf(100 * pageNo));
if (cursor != null) {
cursor.moveToPosition(100 * (pageNo - 1));
while (!cursor.isAfterLast()) {
result.add(loadObject(cursor));
cursor.moveToNext();
if (cursor.moveToPosition(100 * (pageNo - 1))) {
while (!cursor.isAfterLast()) {
result.add(loadObject(cursor));
cursor.moveToNext();
}
}

cursor.close();
}

db.close();
}
}

Expand Down
Binary file removed dist/blueshift-android-sdk-0.6.1.aar
Binary file not shown.
Binary file added dist/blueshift-android-sdk-0.6.2.aar
Binary file not shown.

0 comments on commit 1719844

Please sign in to comment.