我有1700个带有字符串的标记,其中包含地图上每个标记的描述。我收到内存不足错误,因为我为每个标记“点击更多信息”下一个屏幕活动持有这么多字符串。如何才能更好地保存这些数据并在标记点击时共享它而不会出现此内存问题?我从基于XML的文件中提取数据。
这是我崩溃后的错误日志:
10-07 13:42:55.383: D/dalvikvm(4431): GC_FOR_MALLOC freed 1063K, 57% free 9611K/21959K, external 2506K/2804K, paused 77ms
10-07 13:42:57.109: D/dalvikvm(4431): GC_FOR_MALLOC freed 1580K, 56% free 9821K/21959K, external 2551K/2804K, paused 114ms
10-07 13:42:57.320: D/dalvikvm(4431): GC_FOR_MALLOC freed 427K, 55% free 10016K/21959K, external 2365K/2804K, paused 97ms
10-07 13:42:57.656: D/dalvikvm(4431): GC_FOR_MALLOC freed 168K, 54% free 10142K/21959K, external 2365K/2804K, paused 166ms
10-07 13:42:57.804: D/dalvikvm(4431): GC_FOR_MALLOC freed 118K, 54% free 10218K/21959K, external 2365K/2804K, paused 85ms
10-07 13:42:57.922: D/dalvikvm(4431): GC_FOR_MALLOC freed 47K, 54% free 10320K/21959K, external 2365K/2804K, paused 71ms
10-07 13:42:58.031: D/dalvikvm(4431): GC_FOR_MALLOC freed 119K, 54% free 10297K/21959K, external 2365K/2804K, paused 70ms
10-07 13:42:58.148: D/dalvikvm(4431): GC_FOR_MALLOC freed 51K, 53% free 10342K/21959K, external 2365K/2804K, paused 69ms
10-07 13:42:58.148: I/dalvikvm-heap(4431): Grow heap (frag case) to 14.855MB for 33642-byte allocation
10-07 13:42:58.226: D/dalvikvm(4431): GC_FOR_MALLOC freed <1K, 53% free 10375K/22023K, external 2365K/2804K, paused 77ms
10-07 13:42:58.328: D/dalvikvm(4431): GC_FOR_MALLOC freed 83K, 54% free 10343K/22023K, external 2365K/2804K, paused 73ms
10-07 13:42:58.336: I/dalvikvm-heap(4431): Grow heap (frag case) to 14.863MB for 40183-byte allocation
10-07 13:42:58.406: D/dalvikvm(4431): GC_FOR_MALLOC freed 0K, 53% free 10383K/22087K, external 2365K/2804K, paused 72ms
10-07 13:42:58.476: D/dalvikvm(4431): GC_FOR_MALLOC freed 42K, 54% free 10379K/22087K, external 2365K/2804K, paused 71ms
10-07 13:42:58.609: D/dalvikvm(4431): GC_FOR_MALLOC freed 62K, 53% free 10381K/22087K, external 2365K/2804K, paused 78ms
10-07 13:42:58.750: D/dalvikvm(4431): GC_FOR_MALLOC freed 44K, 53% free 10421K/22087K, external 2365K/2804K, paused 79ms
10-07 13:42:58.758: I/dalvikvm-heap(4431): Grow heap (frag case) to 15.005MB for 111024-byte allocation
10-07 13:42:58.844: D/dalvikvm(4431): GC_FOR_MALLOC freed <1K, 53% free 10529K/22215K, external 2365K/2804K, paused 75ms
10-07 13:42:58.961: D/dalvikvm(4431): GC_EXTERNAL_ALLOC freed 10K, 53% free 10528K/22215K, external 2365K/2804K, paused 111ms
10-07 13:42:58.992: E/dalvikvm-heap(4431): 32-byte external allocation too large for this process.
10-07 13:42:58.992: W/OSMemory(4431): External allocation of 32 bytes was rejected
10-07 13:42:59.070: D/dalvikvm(4431): GC_FOR_MALLOC freed 0K, 53% free 10528K/22215K, external 2365K/2804K, paused 68ms
10-07 13:42:59.187: D/dalvikvm(4431): GC_FOR_MALLOC freed 32K, 53% free 10535K/22215K, external 2365K/2804K, paused 69ms
10-07 13:42:59.187: I/dalvikvm-heap(4431): Forcing collection of SoftReferences for 40194-byte allocation
10-07 13:42:59.250: D/dalvikvm(4431): GC_FOR_MALLOC freed <1K, 53% free 10534K/22215K, external 2365K/2804K, paused 67ms
10-07 13:42:59.258: E/dalvikvm-heap(4431): Out of memory on a 40194-byte allocation.
10-07 13:42:59.258: I/dalvikvm(4431): "its_ter" prio=5 tid=13 RUNNABLE
10-07 13:42:59.258: I/dalvikvm(4431): | group="main" sCount=0 dsCount=0 obj=0x4058b398 self=0xfcfe0
10-07 13:42:59.258: I/dalvikvm(4431): | sysTid=4443 nice=10 sched=0/0 cgrp=bg_non_interactive handle=1036568
10-07 13:42:59.258: I/dalvikvm(4431): at java.io.ByteArrayOutputStream.toByteArray(ByteArrayOutputStream.java:~122)
10-07 13:42:59.258: I/dalvikvm(4431): at maps.m.y.a((null):-1)
10-07 13:42:59.258: I/dalvikvm(4431): at maps.k.d.a((null):-1)
10-07 13:42:59.258: I/dalvikvm(4431): at maps.k.g.handleMessage((null):-1)
10-07 13:42:59.265: I/dalvikvm(4431): at android.os.Handler.dispatchMessage(Handler.java:99)
10-07 13:42:59.281: I/dalvikvm(4431): at android.os.Looper.loop(Looper.java:130)
10-07 13:42:59.281: I/dalvikvm(4431): at maps.k.d.c((null):-1)
10-07 13:42:59.281: I/dalvikvm(4431): at maps.ao.b.run((null):-1)
10-07 13:42:59.289: W/System.err(4431): OutOfMemory
10-07 13:42:59.429: D/dalvikvm(4431): GC_EXPLICIT freed 32K, 53% free 10567K/22215K, external 2365K/2804K, paused 128ms
10-07 13:42:59.539: D/dalvikvm(4431): GC_FOR_MALLOC freed 435K, 54% free 10235K/22215K, external 2365K/2804K, paused 75ms
10-07 13:42:59.539: I/dalvikvm-heap(4431): Forcing collection of SoftReferences for 119952-byte allocation
10-07 13:42:59.633: D/dalvikvm(4431): GC_FOR_MALLOC freed 111K, 55% free 10123K/22215K, external 2365K/2804K, paused 97ms
10-07 13:42:59.734: D/dalvikvm(4431): GC_EXTERNAL_ALLOC freed 2K, 54% free 10241K/22215K, external 2365K/2804K, paused 85ms
10-07 13:42:59.765: E/dalvikvm-heap(4431): 32-byte external allocation too large for this process.
10-07 13:42:59.765: W/OSMemory(4431): External allocation of 32 bytes was rejected
10-07 13:42:59.844: D/dalvikvm(4431): GC_FOR_MALLOC freed 0K, 54% free 10241K/22215K, external 2365K/2804K, paused 69ms
10-07 13:42:59.890: W/dalvikvm(4431): threadid=13: thread exiting with uncaught exception (group=0x40015560)
10-07 13:42:59.914: W/dalvikvm(4431): threadid=20: thread exiting with uncaught exception (group=0x40015560)
10-07 13:42:59.922: I/Process(4431): Sending signal. PID: 4431 SIG: 9
我将它们发布在地图上,如下:
BitmapDescriptor icon = BitmapDescriptorFactory
.fromResource(R.drawable.snotel_marker);
int nsize = visibleMarkers.size();
for (int i = 0; i < nsize; i++) {
MapMarkers marks = new MapMarkers();
String title = visibleMarkers.valueAt(i).getTitle();
String desc = visibleMarkers.valueAt(i).getDesc();
Float latitude = visibleMarkers.valueAt(i).getLat();
Float longitude = visibleMarkers.valueAt(i).getLon();
m = map.addMarker(new MarkerOptions()
.position(new LatLng(latitude, longitude))
.title(title).icon(icon));
marks.setTitle(title);
marks.setDesc(desc);
m.setData(marks);
在信息窗口中单击下一个活动填充如下:
getSupportActionBar().setTitle(extras.getString("name"));
webview.loadDataWithBaseURL(null, extras.getString("description"),
"text/html", "utf-8", null);
应用程序在我的GNex上正常运行,但在我的旧Droid上,它填充了地图,然后点击3或4个标记并移动地图后我得到了内存不足错误。我可以分享任何其他输出来试图解决这个问题吗?
从MAT编辑堆转储 - 字符串是根据这个问题:
Problem Suspect 1
9,566 instances of "java.lang.String", loaded by "<system class loader>" occupy 2,299,848 (34.18%) bytes.
Keywords
java.lang.String
Details »
Problem Suspect 2
3,381 instances of "java.lang.Class", loaded by "<system class loader>" occupy 960,088 (14.27%) bytes.
Biggest instances:
•class android.text.Html$HtmlParser @ 0x4018c9d0 - 126,632 (1.88%) bytes.
Keywords
java.lang.Class
Details »