简体   繁体   中英

Mupdf memory leak on Android

I am using the MuPdf library in an Android app and I've notices some memory leaks. When i open a PDF document multiple times (open it, close it, then reopen) I can see the HEAP size grow every time I open the PDF until my app crashes.

I've already seen this question OutOfMemory in MuPdf and tried to implement the provided hotfix without success.

There also seems to be an open bug in MuPdf's bugtracker itself: http://bugs.ghostscript.com/show_bug.cgi?id=695408

The reported bug is open for more than 5 months now and I can't belive that I'm the only one using MuPdf on Android who is having these memory leaks.

Is anyone using MuPdf for android and can help me out?

That bug is reported against MuPDF 1.5 (the current version is 1.6) and the bug reporter has not supplied an example file to investigate with.

There are no known memory leaks in the current version of MuPDF, if you believe you've found one then the best thing to do is to open a bug report. Please be sure and attach a file which exhibits the problem!

Also, you should test this with the standard demo application, if you can't reproduce memory leaks with that, then the problem isn't with MuPDF, but the way that your application is using it. Possibly you aren't freeing everything before you close down.

If you want to ask questions then the MuPDF developers are online in IRC in the #ghostscript channel on irc.freenode.net and are usually able to answer questions. Mostly office hours GMT but sometimes there are people online into the night. The channel is logged so if you can't get there during those hours, put your question and someone will reply when they see it.

I also had this issue with MuPdf with a Mono/Xamarin Android app. As KenS mentioned...

Possibly you aren't freeing everything before you close down.

This was indeed the case for me, and I solved it by calling .destroyDrawingCache() on the ReaderView in the onDestroy() method of the Activity. This appears to be adequate, but if there's anything else I should be doing to release resources from MuPdf please let me know.

C# code example below (should be easily convertible to Java):

private ReaderView _readerView;

...

protected override void OnDestroy()
{
    base.OnDestroy();

    _readerView.DestroyDrawingCache();
    _readerView = null;

    GC.Collect();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM