我在android平台上使用itext阅读pdf并且我正在使用以下代码。但是当我尝试打开大型PDF时,它会在第一行显示内存错误,即 reader = new PdfReader(fileName); 。以下是单击大文件时生成的satck跟踪。
reader = new PdfReader(fileName);
numberOfPages = reader.getNumberOfPages();
System.out.println("This document contains:" + numberOfPages);
extractor = new PdfTextExtractor(reader);
01-23 18:04:50.607: INFO/System.out(428): @@@@!!!/sdcard/Moby_Dick_NT.pdf
external 899K/1038K, paused 202ms
01-23 18:05:31.298: INFO/dalvikvm(428): Jit: resizing JitTable from 1024 to 2048
01-23 18:05:32.947: DEBUG/dalvikvm(428): GC_FOR_MALLOC freed 1678K, 31% free 10361K/14855K, external 899K/1038K, paused 218ms
01-23 18:05:35.657: DEBUG/dalvikvm(428): GC_CONCURRENT freed 2038K, 31% free 10403K/15047K, external 899K/1038K, paused 5ms+10ms
01-23 18:06:00.537: DEBUG/dalvikvm(428): GC_CONCURRENT freed 1845K, 30% free 10625K/15111K, external 899K/1038K, paused 9ms+8ms
01-23 18:06:02.397: DEBUG/dalvikvm(428): GC_FOR_MALLOC freed 1995K, 32% free 10546K/15303K, external 899K/1038K, paused 259ms
01-23 18:06:04.518: DEBUG/dalvikvm(428): GC_CONCURRENT freed 1993K, 32% free 10545K/15303K, external 899K/1038K, paused 9ms+5ms
01-23 18:06:06.468: DEBUG/dalvikvm(428): GC_CONCURRENT freed 1917K, 31% free 10583K/15303K, external 899K/1038K, paused 9ms+5ms
01-23 18:06:08.008: INFO/dalvikvm-heap(428): Clamp target GC heap from 16.145MB to 16.000MB
01-23 18:06:08.008: DEBUG/dalvikvm(428): GC_CONCURRENT freed 1542K, 29% free 10981K/15303K, external 899K/1038K, paused 9ms+5ms
browse.com/.PDFView}
01-23 18:06:09.338: INFO/dalvikvm-heap(428): Clamp target GC heap from 16.498MB to 16.000MB
01-23 18:06:09.338: DEBUG/dalvikvm(428): GC_FOR_MALLOC freed 1370K, 27% free 11342K/15495K, external 899K/1038K, paused 243ms
01-23 18:06:10.437: INFO/dalvikvm-heap(428): Clamp target GC heap from 16.776MB to 16.000MB
01-23 18:06:10.437: DEBUG/dalvikvm(428): GC_FOR_MALLOC freed 1079K, 25% free 11627K/15495K, external 899K/1038K, paused 228ms
01-23 18:06:10.857: INFO/dalvikvm-heap(428): Clamp target GC heap from 16.841MB to 16.000MB
01-23 18:06:10.857: DEBUG/dalvikvm(428): GC_FOR_MALLOC freed 256K, 25% free 11694K/15495K, external 899K/1038K, paused 215ms
01-23 18:06:10.867: INFO/dalvikvm-heap(428): Forcing collection of SoftReferences for 4100-byte allocation
01-23 18:06:11.137: INFO/dalvikvm-heap(428): Clamp target GC heap from 16.827MB to 16.000MB
01-23 18:06:11.137: DEBUG/dalvikvm(428): GC_FOR_MALLOC freed 15K, 25% free 11679K/15495K, external 899K/1038K, paused 272ms
01-23 18:06:11.137: ERROR/dalvikvm-heap(428): Out of memory on a 4100-byte allocation.
01-23 18:06:11.147: INFO/dalvikvm(428): "main" prio=5 tid=1 RUNNABLE
01-23 18:06:11.147: INFO/dalvikvm(428): | group="main" sCount=0 dsCount=0 obj=0x4001f1a8 self=0xce48
答案 0 :(得分:1)
在SO上的另一个线程中有关于内存分配的相关讨论:
我自己没试过,但尝试选项
可能是值得的android:largeHeap="true"
清单中的,因为它击中了16MB的上限。