With a lack of memory, an error occurs here

private Interceptor provideOfflineCacheInterceptor() { return new Interceptor() { @Override public Response intercept(@NonNull Chain chain) throws IOException { Request request = chain.request(); if (!isConnect()) { CacheControl cacheControl = new CacheControl.Builder() .maxStale(DISC_CACHE_LENGTH_DAYS, TimeUnit.DAYS) .build(); request = request.newBuilder() .cacheControl(cacheControl) .build(); } return chain.proceed(request); } }; } 

specifically swears at the line

 return chain.proceed(request); 

here is the stack trace

But it is not released. See java.io.Closeable for information on avoiding resource leaks. java.lang.Throwable: Explicit termination method is not called at dalvik.system.CloseGuard.open (CloseGuard.java:223) at java.io.FileOutputStream. (FileOutputStream.java:224) at okio.Okio.appendingSink ( Okio.java:186) at okhttp3.internal.io.FileSystem $ 1.appendingSink (FileSystem.java:59) at okhttp3.internal.cache.DiskLruCache.newJournalWriter (DiskLruCache.java.7015) at okhttp3.internal.cache.DiskLruCache. readJournal (DiskLruCache.java:307) at okhttp3.internal.cache.DiskLruCache.initialize (DiskLruCache.java:228) at okhttp3.internal.cache.DiskLruCache.get (DiskLruCache.java penet36) at okhttp3.Cache.get (Cache .java: 195) at okhttp3.Cache $ 1.get (Cache.java:145)

With enough memory, everything is working fine. How to fix the problem mono?

    1 answer 1

    This means that you have discovered something, but never close it. Closable has a close method that you must call to release the resources associated with a component when you no longer need it.

    To find a leak, you can try Memory Analyzer (MAT) , you can use it to look for memory leaks (static data containing a link to an Activity, etc.). From here https://stackoverflow.com/questions/25544021/a-resource-was-acquired-at-attached-stack-trace-but-never-released-see-java-io

    • there is no need to look for an obvious leak here as it is possible to avoid it with Interceptor - krekerkreker07