OutOfMemory in MuPdf

2019-07-06 07:06发布

Hello I am using MuPdf library in my project to view documents. The problem is that when you open 3-7 documents in a activity 11 inches on the tablet, i get memory overflow. When you load a new document, all references to the previous document are destroyed, but the image of the document from memory are not removed. objects are created in the memory image of 10-12 megabytes. on tablet the size of 7 inches this problem does not arise.

Maybe someone encountered this problem?

标签: android mupdf
4条回答
干净又极端
2楼-- · 2019-07-06 07:14

I added the following code to force garbage collector in PageView.java and it seems to work okay so far.

if (mEntireBm == null || mEntireBm.getWidth() != newSize.x
                              || mEntireBm.getHeight() != newSize.y) {
            mEntireBm = Bitmap.createBitmap(mSize.x, mSize.y, Bitmap.Config.ARGB_8888);
            System.gc();//Added
            Runtime.getRuntime().gc();//Added
        }

Edited: it crashes after open the file several times

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-07-06 07:15

This problem is resolved by calling recycle() on bitmap in relaeseBitmaps() method of PageView.java

public void releaseBitmaps() {
        reinit();
        mEntireBm.recycle();
        mPatchBm.recycle();
        mEntireBm = null;
        mPatchBm = null;
    }
查看更多
Luminary・发光体
4楼-- · 2019-07-06 07:18

Inside mupdf.c find

"/* 128 MB store for low memory devices. Tweak as necessary. */" and

change the memory limit and try

I tried with 512 the rendering is faster than before

查看更多
该账号已被封号
5楼-- · 2019-07-06 07:33
  1. Edit mupdf.c

Change: /* 128 MB store for low memory devices. Tweak as necessary. */ glo->ctx = ctx = fz_new_context(NULL, NULL, 128 << 20); to /* 128 MB store for low memory devices. Tweak as necessary. */ glo->ctx = ctx = fz_new_context(NULL, NULL, 32 << 20);

That`s all. Max heap memory amount ~50Mb.

查看更多
登录 后发表回答