DImuthuUpe / AndroidPdfViewer

Android view for displaying PDFs rendered with PdfiumAndroid
Apache License 2.0
8.18k stars 1.91k forks source link

OutOfMemoryError at android-pdf-viewer:3.1.0-beta.1 #688

Open chentangchun opened 6 years ago

chentangchun commented 6 years ago

W/dalvikvm: threadid=31: thread exiting with uncaught exception (group=0x94cffb20) E/AndroidRuntime: FATAL EXCEPTION: PDF renderer Process: com.****, PID: 2195 java.lang.OutOfMemoryError at android.graphics.Bitmap.nativeCreate(Native Method) at android.graphics.Bitmap.createBitmap(Bitmap.java:809) at android.graphics.Bitmap.createBitmap(Bitmap.java:786) at android.graphics.Bitmap.createBitmap(Bitmap.java:753) at com.github.barteksc.pdfviewer.RenderingHandler.proceed(RenderingHandler.java:102) at com.github.barteksc.pdfviewer.RenderingHandler.handleMessage(RenderingHandler.java:66) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.os.HandlerThread.run(HandlerThread.java:61)

chentangchun commented 6 years ago

我添加了下面的代码,后面好像又没有报此异常了: pdfView.useBestQuality(false); Constants.Cache.CACHE_SIZE = 40;’

Yazon2006 commented 6 years ago

@barteksc Current implementation of cache manager is not quite right, 'cause different devices can have different amount of free RAM at some moments. My suggestion is to implement CacheManager using LRUCache and avoid allocating memory for bitmaps. https://developer.android.com/topic/performance/graphics/manage-memory

clevertrevor commented 5 years ago

@chentangchun 's comment (translated by Google)

I added the following code, and it seems that I have not reported this exception. pdfView.useBestQuality(false); Constants.Cache.CACHE_SIZE = 40;’

This fix worked for me on a Samsung Galaxy Tab A7 with 1.5Gb memory.