问题
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:
- 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