Summary: | memory leaks in mupdf for android | ||
---|---|---|---|
Product: | MuPDF | Reporter: | palmicq |
Component: | mupdf | Assignee: | Robin Watts <robin.watts> |
Status: | RESOLVED FIXED | ||
Severity: | normal | CC: | abun.santo, jackie.rosen, palmicq, robin.watts, vk872903, W90043, yultae |
Priority: | P4 | ||
Version: | unspecified | ||
Hardware: | Other | ||
OS: | other | ||
Customer: | Word Size: | --- |
Description
palmicq
2011-06-13 15:44:26 UTC
I can't see any obvious memory leaks (although, that's not to say there aren't any). If I download the image into the emulator (with pdf_reference17.pdf as the test file) and start it up, then do: adb shell dumpsys meminfo com.artifex.mupdf It tells me that I have a total of 17240K allocated after the first page is displayed. If I then step forward (click next repeatedly) to page 100, the same thing tells me that I have 20544K allocated. Return to page 1, and I have 21000K. If I repeat this again and again, I asymptotically reach 21338K or so. We expect memory to increase for every *new* page that is displayed, as mupdf has to hold the positions/lengths etc of all the different stream objects used in each new page. This explains why the memory use climbs as we move forward to page 100. Fragmentation explains why we see the memory usage climb a bit even when we tread backwards over pages we have seen before. On the whole it looks like we aren't losing memory purely by changing from one page to another. I think there *may* be a memory leak to do with exiting the app and then restarting it as the total memory seems to jump significantly every time I exit and restart. I've fixed the 'restarting app causing large leak' problem. A patch should be working its way towards the main repo as we speak. If this doesn't solve the problem, please reopen the bug with some more details, including exactly the file you are using and step by step instructions allowing me to reproduce what you are doing here. (In particular how you are measuring the memory usage). Thanks. Hi Robin, Should colorspace needs to be freed in Java_com_artifex_mupdf_MuPDFCore_destroying(JNIEnv * env, jobject thiz)? like this: fz_drop_colorspace(colorspace); colorspace = NULL; Thanks. (In reply to comment #3) > Should colorspace needs to be freed in > Java_com_artifex_mupdf_MuPDFCore_destroying(JNIEnv * env, jobject thiz)? No, because that's a pointer to a statically allocated thing. Comparing to the pdfapp.c, two lines are added. currentRotate = currentPage->rotate; currentPage->links = NULL; // added .. fz_free_device(dev); pdf_age_store(xref->store, 3); // added Memory leaks looks to be gone. May help. (In reply to comment #5) > Comparing to the pdfapp.c, two lines are added. > > currentRotate = currentPage->rotate; > currentPage->links = NULL; // added > .. > fz_free_device(dev); > pdf_age_store(xref->store, 3); // added > > Memory leaks looks to be gone. > > May help. Can you specify which portion in pdfapp.c needs to be change? I can not find any place in pdfapp.c saying currentRotate = currentPage->rotate. (In reply to comment #5) > Comparing to the pdfapp.c, two lines are added. > > currentRotate = currentPage->rotate; > currentPage->links = NULL; // added > .. > fz_free_device(dev); > pdf_age_store(xref->store, 3); // added > > Memory leaks looks to be gone. > > May help. Cool! The cache limitation function works for me. Thank you! (In reply to comment #6) > (In reply to comment #5) > > Comparing to the pdfapp.c, two lines are added. > > > > currentRotate = currentPage->rotate; > > currentPage->links = NULL; // added > > .. > > fz_free_device(dev); > > pdf_age_store(xref->store, 3); // added > > > > Memory leaks looks to be gone. > > > > May help. > > Can you specify which portion in pdfapp.c needs to be change? I can not find > any place in pdfapp.c saying currentRotate = currentPage->rotate. I add those two lines but the app still crashes. I open a 300 Mb pdf and can only access first 2 pages Hi palmicq@gmail.com do you check your Android memory when loading pdf? I'm using the patch in #comment 6, still having problem in the #comment 1. Hi William Lee, do your issue solved? Thanks Hi palmicq@gmail.com do you check your Android memory when loading pdf? I'm using the patch in #comment 6, still having problem in the #comment 1. Hi William Lee, do your issue solved? Thanks (In reply to comment #7) > (In reply to comment #5) > > Comparing to the pdfapp.c, two lines are added. > > > > currentRotate = currentPage->rotate; > > currentPage->links = NULL; // added > > .. > > fz_free_device(dev); > > pdf_age_store(xref->store, 3); // added > > > > Memory leaks looks to be gone. > > > > May help. > > Cool! The cache limitation function works for me. Thank you! Hi may I know the file name where should I add this code to. Or could you please send me the updated file. Thank you. |