Since I started to use SimpleCache with ExoPlayer I keep getting LeakedCloseableViolation, as soon as I start playing a new file even though I’m calling the cache release method.
Here’s how I’m initializing the player
...
this.simpleCache = new SimpleCache(new File(context.getCacheDir(), "streamCaching"), new LeastRecentlyUsedCacheEvictor(25 * 1024 * 1024), new StandaloneDatabaseProvider(context));
factory = new CacheDataSource.Factory().setCache(this.simpleCache).setUpstreamDataSourceFactory(httpDataSourceFactory);
...
Then here’s my release code that is called as soon as the player is stopped
this.player.release();
if (this.simpleCache != null) {
this.simpleCache.release();
this.simpleCache = null;
}
Any idea why I keep getting these
StrictMode policy violation: android.os.strictmode.LeakedClosableViolation: A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
at android.os.StrictMode$AndroidCloseGuardReporter.report(StrictMode.java:1987)
at dalvik.system.CloseGuard.warnIfOpen(CloseGuard.java:345)
at android.database.sqlite.SQLiteDatabase.dispose(SQLiteDatabase.java:427)
at android.database.sqlite.SQLiteDatabase.finalize(SQLiteDatabase.java:408)
at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:291)
at java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:278)
at java.lang.Daemons$Daemon.run(Daemons.java:139)
at java.lang.Thread.run(Thread.java:920)
Caused by: java.lang.Throwable: Explicit termination method ‘close’ not called
at dalvik.system.CloseGuard.openWithCallSite(CloseGuard.java:295)
at dalvik.system.CloseGuard.open(CloseGuard.java:263)
at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:1415)
at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:1355)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:996)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:470)
at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:437)
at com.google.android.exoplayer2.upstream.cache.CachedContentIndex$DatabaseStorage.exists(CachedContentIndex.java:799)
at com.google.android.exoplayer2.upstream.cache.CachedContentIndex.initialize(CachedContentIndex.java:201)
at com.google.android.exoplayer2.upstream.cache.SimpleCache.initialize(SimpleCache.java:582)
at com.google.android.exoplayer2.upstream.cache.SimpleCache.access$000(SimpleCache.java:49)
at com.google.android.exoplayer2.upstream.cache.SimpleCache$1.run(SimpleCache.java:268)