1

我有一个活动,只是在地图(google android v2 api)和图像之间切换。我使用 MapFragment。出于某种原因,即使我尝试执行 map.clear(),它仍然会保留内存。如您所见,每次显示映射时,我在内存映射中都有一个新的 maps.za 实例。如何清除这些?我也尝试过手动运行 System.gc() 。

Class Name                                                   | Shallow Heap | Retained Heap | Percentage
---------------------------------------------------------------------------------------------------------
                                                             |              |               |           
class android.content.res.Resources @ 0x41267910 System Class|           40 |     8,526,400 |     39.29%
android.graphics.Bitmap @ 0x421b0620                         |           48 |     5,760,064 |     26.54%
android.graphics.Bitmap @ 0x415a33e0                         |           48 |     1,127,600 |      5.20%
maps.as.aw @ 0x434a6750                                      |          160 |       278,072 |      1.28%
maps.p.c @ 0x421b4110                                        |           32 |       211,040 |      0.97%
maps.z.a @ 0x4218f698                                        |          152 |       205,864 |      0.95%
maps.z.a @ 0x421f69a8                                        |          152 |       205,256 |      0.95%
maps.z.a @ 0x4222f5c8                                        |          152 |       205,256 |      0.95%
maps.z.a @ 0x4366fb20                                        |          152 |       205,256 |      0.95%
android.graphics.Bitmap @ 0x41feb6e0                         |           48 |       160,064 |      0.74%
java.util.zip.ZipFile @ 0x42155b40                           |           32 |       139,704 |      0.64%
maps.as.q @ 0x41f35e30                                       |           80 |       131,536 |      0.61%
maps.as.q @ 0x421dcad8                                       |           80 |       131,536 |      0.61%
maps.as.q @ 0x434e7d90                                       |           80 |       131,536 |      0.61%
maps.as.q @ 0x435ccc40                                       |           80 |       131,536 |      0.61%
maps.as.aw @ 0x420c5e90                                      |          160 |       127,944 |      0.59%
class android.text.Html$HtmlParser @ 0x41e18f98 System Class |            8 |       126,632 |      0.58%
maps.as.aw @ 0x435bc4e0                                      |          160 |       111,624 |      0.51%
android.graphics.Bitmap @ 0x415e6708                         |           48 |       100,304 |      0.46%
class libcore.icu.TimeZones @ 0x4123d1e8 System Class        |           40 |        90,080 |      0.42%
---------------------------------------------------------------------------------------------------------

代码段:

添加到视图

frag = MapFragment.newInstance();
// Add the MapFragment to the view
FragmentTransaction ft = ((Activity) context).getFragmentManager().beginTransaction();
ft.add(this.getId(), frag).commit();

从视图中移除

FragmentTransaction ft = ((Activity) context).getFragmentManager().beginTransaction();
ft.remove(frag).commit();
4

0 回答 0