OutOfMemory in MuPdf

北城余情 提交于 2019-12-13 13:41:44

问题


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?


回答1:


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;
    }



回答2:


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:


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




回答4:


  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.



来源:https://stackoverflow.com/questions/10306569/outofmemory-in-mupdf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!