Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak in SqliteJobQueue.loadTags(SqliteJobQueue.java:439) #223

Closed
mwajeeh opened this issue Aug 4, 2016 · 1 comment
Closed

Memory leak in SqliteJobQueue.loadTags(SqliteJobQueue.java:439) #223

mwajeeh opened this issue Aug 4, 2016 · 1 comment

Comments

@mwajeeh
Copy link

mwajeeh commented Aug 4, 2016

I started getting out of memory exceptions in my app:

android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed

Following this advice I added following snippet in my Application class:

 if (BuildConfig.DEBUG) {
            StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
                    .detectLeakedSqlLiteObjects()
                    .detectLeakedClosableObjects()
                    .penaltyLog()
                    .penaltyDeath()
                    .build());
 }

And my app started crashing immediately with following log:

A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
java.lang.Throwable: Explicit termination method 'close' not called
at dalvik.system.CloseGuard.open(CloseGuard.java:180)
at android.database.CursorWindow.(CursorWindow.java:111)
at android.database.AbstractWindowedCursor.clearOrCreateWindow(AbstractWindowedCursor.java:198)
at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:138)
at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:132)
at com.birbit.android.jobqueue.persistentQueue.sqlite.SqliteJobQueue.loadTags(SqliteJobQueue.java:439)
at com.birbit.android.jobqueue.persistentQueue.sqlite.SqliteJobQueue.createJobHolderFromCursor(SqliteJobQueue.java:416)
at com.birbit.android.jobqueue.persistentQueue.sqlite.SqliteJobQueue.nextJobAndIncRunCount(SqliteJobQueue.java:294)
at com.birbit.android.jobqueue.cachedQueue.CachedJobQueue.nextJobAndIncRunCount(CachedJobQueue.java:79)
at com.birbit.android.jobqueue.JobManagerThread.getNextJob(JobManagerThread.java:652)
at com.birbit.android.jobqueue.JobManagerThread.getNextJob(JobManagerThread.java:629)
at com.birbit.android.jobqueue.ConsumerManager.handleIdle(ConsumerManager.java:190)
at com.birbit.android.jobqueue.JobManagerThread$1.handleMessage(JobManagerThread.java:228)
at com.birbit.android.jobqueue.messaging.PriorityMessageQueue.consume(PriorityMessageQueue.java:39)
at com.birbit.android.jobqueue.JobManagerThread.run(JobManagerThread.java:220)
at java.lang.Thread.run(Thread.java:761)

The crash is happening here SqliteJobQueue.loadTags(SqliteJobQueue.java:439) which makes sense because even if cursor.getCount() == 0 is true, cursor is still there and it must be explicitly closed.

IMHO you should add StrictMode snippet to your code too to detect such leaks.

BTW thanks for this awesome library.

@yigit
Copy link
Owner

yigit commented Aug 5, 2016

Thanks for the report. This was already fixed here: #206 . I'm guessing you are not using beta2 ?

@yigit yigit added the duplicate label Aug 5, 2016
@yigit yigit closed this as completed Aug 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants