DImuthuUpe / AndroidPdfViewer

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

FATAL EXCEPTION: PDF renderer java.lang.OutOfMemoryError #395

Open Kerace opened 7 years ago

Kerace commented 7 years ago

After I open PDF File,(using this pdf.fromFile()) When i roll several times,it will throws OOM exception. my file size is 700kb. I think this is related to my phone?

The error log is as follows:

E/AndroidRuntime: FATAL EXCEPTION: PDF renderer java.lang.OutOfMemoryError at android.graphics.Bitmap.nativeCreate(Native Method) at android.graphics.Bitmap.createBitmap(Bitmap.java:650) at android.graphics.Bitmap.createBitmap(Bitmap.java:630) at com.github.barteksc.pdfviewer.RenderingHandler.proceed(RenderingHandler.java:96) at com.github.barteksc.pdfviewer.RenderingHandler.handleMessage(RenderingHandler.java:71) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.os.HandlerThread.run(HandlerThread.java:60)

barteksc commented 7 years ago

Which version do you use?

bestbobgit commented 7 years ago

Here`s the same issue on android 4.4 , (4.4.4 / 4.4.2)many times,
AndroidPdfViewer 2.6.1

Kerace commented 7 years ago

My version is 'com.github.barteksc:android-pdf-viewer:2.7.0-beta.1'

barteksc commented 7 years ago

@Kerace Do you use pdfView.useBestQuality(true)?

Kerace commented 7 years ago
            pdfView.fromFile(pdf)
                    .defaultPage(pageNumber)
                    .onPageChange(new OnPageChangeListener() {
                        @Override
                        public void onPageChanged(int page, int pageCount) {
                            pageNumber = page;
                        }
                    })
                    .enableAnnotationRendering(false)
                    .enableAntialiasing(true)
                    .scrollHandle(new DefaultScrollHandle(getContext()))
                    .spacing(10)
                    .load();

@barteksc I think I did not use it,and I try to setting pdfView.useBestQuality(false); My AOS is 4.1.1.

microsoftBoy commented 6 years ago

Have you solved this problem yet?I met the same problem, when I repeated or narrowed up and down again and again.I have set up pdfView.useBestQuality (false);

1stmetro commented 6 years ago

If you share the pdf I can test on a few devices different os.

microsoftBoy commented 6 years ago

@1stmetro thank you ,I've solved this problem.just change the size of the cache, as follows: public static class Cache {

    /** The size of the cache (number of bitmaps kept) */
    public static int CACHE_SIZE = 40;

    public static int THUMBNAILS_CACHE_SIZE = 8;
}
1stmetro commented 6 years ago

I believe my cache size is dynamicically based upon the device.

I'm guessing that device has a small amount of ram.

microsoftBoy commented 6 years ago

yes,you are right.The ram of my device is really small.

microsoftBoy commented 6 years ago

I still have this problem when I use it in viewpager。Only the probability of the appearance is smaller.

SunnyTang commented 6 years ago

i also met this issues on AndroidPdfViewer 3.0.0, is there any solution?

microsoftBoy commented 6 years ago

@SunnyTang 我把CACHE_SIZE改成30之后,目前没有再出现过

SunnyTang commented 6 years ago

@microsoftBoy 谢谢!现在有相应的接口可以设置这个值吗?

microsoftBoy commented 6 years ago

@SunnyTang 我是通过源码依赖,本地修改的,你也可以尝试下直接为CACHE_SIZE赋值,应该也是可以的

tianshaokai commented 6 years ago

大家打包都是用的哪个版本呢,咱们国内有没有QQ交流群呢 交流AndroidPdfViewer 使用

chentangchun commented 6 years ago

i also met this issues on AndroidPdfViewer 3.1.0-beta.1,has any solution?