0


我有一个想要运行的动画,当我为其设置可绘制对象时,出现了内存泄漏。我不知道这是否重要,但框架仅在可绘制文件夹中,而不在特定的 dpi 文件夹中。甚至在我开始动画之前就发生了内存泄漏。当我设置动画的资源时会发生这种情况。谢谢!

来电:

logoAnimation.setBackgroundResource(R.drawable.logo_animation);

logo_animation.xml:

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">

    <item android:drawable="@drawable/logo0" android:duration="35" />
    <item android:drawable="@drawable/logo1" android:duration="35" />
    <item android:drawable="@drawable/logo2" android:duration="35" />
    <item android:drawable="@drawable/logo3" android:duration="35" />
    <item android:drawable="@drawable/logo4" android:duration="35" />
    <item android:drawable="@drawable/logo5" android:duration="35" />
    <item android:drawable="@drawable/logo6" android:duration="35" />
    <item android:drawable="@drawable/logo7" android:duration="35" />
    <item android:drawable="@drawable/logo8" android:duration="35" />
    <item android:drawable="@drawable/logo9" android:duration="35" />
    <item android:drawable="@drawable/logo10" android:duration="35" />
    <item android:drawable="@drawable/logo11" android:duration="35" />
    <item android:drawable="@drawable/logo12" android:duration="35" />
    <item android:drawable="@drawable/logo13" android:duration="35" />
    <item android:drawable="@drawable/logo14" android:duration="35" />
    <item android:drawable="@drawable/logo15" android:duration="35" />
    <item android:drawable="@drawable/logo16" android:duration="35" />
    <item android:drawable="@drawable/logo17" android:duration="35" />
    <item android:drawable="@drawable/logo18" android:duration="35" />
    <item android:drawable="@drawable/logo19" android:duration="35" />
    <item android:drawable="@drawable/logo20" android:duration="35" />
    <item android:drawable="@drawable/logo21" android:duration="35" />
    <item android:drawable="@drawable/logo22" android:duration="35" />
    <item android:drawable="@drawable/logo23" android:duration="35" />
    <item android:drawable="@drawable/logo24" android:duration="35" />
    <item android:drawable="@drawable/logo25" android:duration="35" />
    <item android:drawable="@drawable/logo26" android:duration="35" />
    <item android:drawable="@drawable/logo27" android:duration="35" />
    <item android:drawable="@drawable/logo28" android:duration="35" />
    <item android:drawable="@drawable/logo29" android:duration="35" />
    <item android:drawable="@drawable/logo30" android:duration="35" />
    <item android:drawable="@drawable/logo31" android:duration="35" />
    <item android:drawable="@drawable/logo32" android:duration="35" />
    <item android:drawable="@drawable/logo33" android:duration="35" />
    <item android:drawable="@drawable/logo34" android:duration="35" />
    <item android:drawable="@drawable/logo35" android:duration="35" />
    <item android:drawable="@drawable/logo36" android:duration="35" />
    <item android:drawable="@drawable/logo37" android:duration="35" />
    <item android:drawable="@drawable/logo38" android:duration="35" />
    <item android:drawable="@drawable/logo39" android:duration="35" />
    <item android:drawable="@drawable/logo40" android:duration="35" />
    <item android:drawable="@drawable/logo41" android:duration="35" />
    <item android:drawable="@drawable/logo42" android:duration="35" />
    <item android:drawable="@drawable/logo43" android:duration="35" />
    <item android:drawable="@drawable/logo44" android:duration="35" />
    <item android:drawable="@drawable/logo45" android:duration="35" />
    <item android:drawable="@drawable/logo46" android:duration="35" />
    <item android:drawable="@drawable/logo47" android:duration="35" />
    <item android:drawable="@drawable/logo48" android:duration="35" />
    <item android:drawable="@drawable/logo49" android:duration="35" />
    <item android:drawable="@drawable/logo50" android:duration="35" />
    <item android:drawable="@drawable/logo51" android:duration="35" />
    <item android:drawable="@drawable/logo52" android:duration="35" />
    <item android:drawable="@drawable/logo53" android:duration="35" />
    <item android:drawable="@drawable/logo54" android:duration="35" />
    <item android:drawable="@drawable/logo55" android:duration="35" />
    <item android:drawable="@drawable/logo56" android:duration="35" />
    <item android:drawable="@drawable/logo57" android:duration="35" />
    <item android:drawable="@drawable/logo58" android:duration="35" />
    <item android:drawable="@drawable/logo59" android:duration="35" />

</animation-list>

日志输出:

08-08 12:42:10.710: D/dalvikvm(6122): GC_CONCURRENT freed <1K, 3% free 10269K/10567K, paused 2ms+1ms
08-08 12:42:13.135: D/dalvikvm(6122): GC_FOR_ALLOC freed 115K, 3% free 10490K/10759K, paused 10ms
08-08 12:42:13.160: D/dalvikvm(6122): GC_FOR_ALLOC freed 130K, 4% free 10781K/11143K, paused 9ms
08-08 12:42:13.215: D/dalvikvm(6122): GC_FOR_ALLOC freed 195K, 4% free 11155K/11527K, paused 25ms
08-08 12:42:13.265: D/dalvikvm(6122): GC_FOR_ALLOC freed 130K, 4% free 11512K/11911K, paused 20ms
08-08 12:42:13.295: D/dalvikvm(6122): GC_FOR_ALLOC freed 195K, 4% free 11951K/12423K, paused 10ms
08-08 12:42:13.325: D/dalvikvm(6122): GC_FOR_ALLOC freed 260K, 4% free 12535K/12999K, paused 9ms
08-08 12:42:13.360: D/dalvikvm(6122): GC_FOR_ALLOC freed 325K, 4% free 13266K/13767K, paused 9ms
08-08 12:42:13.400: D/dalvikvm(6122): GC_FOR_ALLOC freed 391K, 4% free 14143K/14727K, paused 9ms
08-08 12:42:13.450: D/dalvikvm(6122): GC_FOR_ALLOC freed 521K, 5% free 15313K/16071K, paused 10ms
08-08 12:42:13.510: D/dalvikvm(6122): GC_FOR_ALLOC freed 587K, 5% free 16628K/17415K, paused 10ms
08-08 12:42:13.570: D/dalvikvm(6122): GC_FOR_ALLOC freed 587K, 5% free 17942K/18759K, paused 10ms
4

1 回答 1

0

您正在加载相当多的图像,大约 60 个。如果这些图像也比较大,这让我认为内存泄漏是由OutOfMemoryException.

这是一篇关于如何处理它的好文章。
简而言之,这个想法是您应该在将图像加载到内存之前按比例缩小它们。

于 2012-08-08T09:53:54.770 回答