可能使用 ActivityGroup 的 Android 内存使用问题

发布于 2024-10-19 11:21:00 字数 9383 浏览 8 评论 0原文

可能使用 ActivityGroup 时的 Android 内存使用问题

这是一个有点长的故事,我最终搞砸了内存问题。我通过使用大量的活动和框架开发了非常深入的 Android 应用程序。首先我不得不说我使用 ActivityGroups 作为主要类别来轻松处理活动。我可以通过 getLocalActivityManager() 实现所有活动。我收到此错误消息:

02-25 11:34:13.749:
ERROR/dalvikvm-heap(3042):
2764800-byte external allocation too
large for this process.

02-25 11:34:13.749:
ERROR/GraphicsJNI(3042): VM won't let
us allocate 2764800 bytes

然后我的应用程序将因各种异常而崩溃,例如;

02-25 11:34:13.772: ERROR/AndroidRuntime(3042): FATAL EXCEPTION: main
02-25 11:34:13.772: ERROR/AndroidRuntime(3042): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.turkcell.seyahat/com.matriksdata.ui.schedule.MessageDetail}: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.app.ActivityThread.startActivityNow(ActivityThread.java:2503)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at com.matriksdata.app.XActivityGroup.goForward(XActivityGroup.java:122)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at com.matriksdata.ui.parents.ScheduleActivityGroup.goForward(ScheduleActivityGroup.java:143)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at com.matriksdata.ui.schedule.MessageBox.onItemClick(MessageBox.java:81)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.widget.AdapterView.performItemClick(AdapterView.java:284)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.widget.ListView.performItemClick(ListView.java:3730)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.widget.AbsListView$PerformClick.run(AbsListView.java:1808)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.os.Handler.handleCallback(Handler.java:587)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.os.Handler.dispatchMessage(Handler.java:92)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.os.Looper.loop(Looper.java:123)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.app.ActivityThread.main(ActivityThread.java:4627)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at java.lang.reflect.Method.invokeNative(Native Method)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at java.lang.reflect.Method.invoke(Method.java:521)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:871)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at dalvik.system.NativeStart.main(Native Method)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.view.LayoutInflater.createView(LayoutInflater.java:513)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:210)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.app.Activity.setContentView(Activity.java:1647)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at com.matriksdata.ui.schedule.MessageDetail.onCreate(MessageDetail.java:33)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     ... 18 more
02-25 11:34:13.772: ERROR/AndroidRuntime(3042): Caused by: java.lang.reflect.InvocationTargetException
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.widget.LinearLayout.<init>(LinearLayout.java:115)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at java.lang.reflect.Constructor.constructNative(Native Method)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.view.LayoutInflater.createView(LayoutInflater.java:500)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     ... 28 more
02-25 11:34:13.772: ERROR/AndroidRuntime(3042): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.graphics.Bitmap.nativeCreate(Native Method)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.graphics.Bitmap.createBitmap(Bitmap.java:468)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.graphics.Bitmap.createBitmap(Bitmap.java:435)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:340)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:590)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:564)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:425)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.content.res.Resources.loadDrawable(Resources.java:1709)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.view.View.<init>(View.java:1885)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.view.View.<init>(View.java:1834)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.view.ViewGroup.<init>(ViewGroup.java:285)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     ... 32 more

当然,我没有 2764800 字节 png 图像,但我认为它的解码大小。所以我认为我遇到了图像处理问题,我检查并修复了我的项目的每个细节,以正确处理图像。我检查了 android-developers.blogspot.com/2009/01/avoiding-memory-leaks.html 中描述的所有内容。我检查了空可绘制对象,遵循模型可重用性说明,更改了以下描述的加载方法:stackoverflow.com/questions/477572/android-strange-out-of-memory-issue/823966#823966。

我也有一些位图可以从磁盘加载。我的所有布局都是由 android xml 布局文件创建的。我还有大量在 xml 文件中描述的位图。

然后我看到我在内存分析器的应用程序中有很大的静态类。我通过按需加载并在使用后释放来释放静态属性。所以最后我在 MAT 中得到了内存泄漏的嫌疑;

问题嫌疑人 1

由“”加载的“java.lang.Class”的 3,043 个实例占用 871,304 (17.97%) 字节。

最大实例:
com.ibm.icu4jni.util.Resources$DefaultTimeZones 类 @ 0x4014c3b0- 166,768 (3.44%) 字节。
类 android.text.Html$HtmlParser @ 0x400fe448 - 126,592 (2.61%) 字节。
com.google.googlenav.proto.GmmMessageTypes 类 @ 0x4835d450- 56,944 (1.17%) 字节。
类 org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool @ 0x47caea20 - 51,872 (1.07%) 字节。
org.apache.harmony.security.fortress.Services 类 @ 0x4008c4d0 - 51,456 (1.06%) 字节。

问题嫌疑人 2

由“系统类加载器”加载的 8,721 个“java.lang.String”实例占用 549,624 (11.33%) 字节。 关键字 java.lang.String

问题嫌疑人 3

由“系统类加载器”加载的 60 个“org.bouncycastle.jce.provider.X509CertificateObject”实例占用 300,024 (10.76%) 字节。这些实例是从“java.util.Hashtable$HashtableEntry[]”的一个实例引用的,由“系统类加载器”加载 关键字 org.bouncycastle.jce.provider.X509CertificateObject java.util.Hashtable$HashtableEntry[]

这第三个不是每次都会发生。通常当我在 GalaxyTab 中使用内存管理器时。

我最大的顶级统治者课程是这些。 http://www .matriks.mobi/arge/android/Screen%20shot%202011-02-25%20at%2012.19.08%20PM.png

我只有 2 或 3 个活动正在进行,其余的都已暂停。我在组件报告中收到此消息。当然,这并不是我只使用 1.5 MB 内存的解释,因为根据内存管理器,我的应用程序使用的内存从大约 20 MB 增加到了 48 MB。

可能的内存浪费 *重复字符串* 发现 char[] 出现 0 次,其中至少 10 个实例具有相同的内容。总大小为 0 字节。

我认为这不是我想要的:) hprof 文件位于 http:// www.matriks.mobi/arge/android/android5706014442078310727.hprof.zip

我猜我对 ActivityGroup 类有问题。至少我将 LocalActivityManager 中的活动和活动 ID 保留在堆栈中。但即使我不创建新的活动,并在加载的活动之间传递,内存也会增加。

我知道这不是搜索泄漏的方式,并且可能我有一个基于代码的问题导致此内存泄漏。但我应该检查的任何一个想法都会在这里非常受欢迎,因为我有点被困在这里。

Android Memory Usage Problem on possibly using ActivityGroup

This is a little bit long story that i ended up messing with memory problems. I developed very deep android application by using very amount of Activities and Frameworks. First of all I have to say I used ActivityGroups for main categories to handle activities easily. And I can achieve all activities via getLocalActivityManager(). And I get this error message:

02-25 11:34:13.749:
ERROR/dalvikvm-heap(3042):
2764800-byte external allocation too
large for this process.

02-25 11:34:13.749:
ERROR/GraphicsJNI(3042): VM won't let
us allocate 2764800 bytes

then my application will crash with various exceptions, eg;

02-25 11:34:13.772: ERROR/AndroidRuntime(3042): FATAL EXCEPTION: main
02-25 11:34:13.772: ERROR/AndroidRuntime(3042): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.turkcell.seyahat/com.matriksdata.ui.schedule.MessageDetail}: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.app.ActivityThread.startActivityNow(ActivityThread.java:2503)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at com.matriksdata.app.XActivityGroup.goForward(XActivityGroup.java:122)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at com.matriksdata.ui.parents.ScheduleActivityGroup.goForward(ScheduleActivityGroup.java:143)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at com.matriksdata.ui.schedule.MessageBox.onItemClick(MessageBox.java:81)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.widget.AdapterView.performItemClick(AdapterView.java:284)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.widget.ListView.performItemClick(ListView.java:3730)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.widget.AbsListView$PerformClick.run(AbsListView.java:1808)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.os.Handler.handleCallback(Handler.java:587)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.os.Handler.dispatchMessage(Handler.java:92)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.os.Looper.loop(Looper.java:123)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.app.ActivityThread.main(ActivityThread.java:4627)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at java.lang.reflect.Method.invokeNative(Native Method)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at java.lang.reflect.Method.invoke(Method.java:521)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:871)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at dalvik.system.NativeStart.main(Native Method)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.view.LayoutInflater.createView(LayoutInflater.java:513)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:210)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.app.Activity.setContentView(Activity.java:1647)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at com.matriksdata.ui.schedule.MessageDetail.onCreate(MessageDetail.java:33)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     ... 18 more
02-25 11:34:13.772: ERROR/AndroidRuntime(3042): Caused by: java.lang.reflect.InvocationTargetException
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.widget.LinearLayout.<init>(LinearLayout.java:115)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at java.lang.reflect.Constructor.constructNative(Native Method)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.view.LayoutInflater.createView(LayoutInflater.java:500)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     ... 28 more
02-25 11:34:13.772: ERROR/AndroidRuntime(3042): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.graphics.Bitmap.nativeCreate(Native Method)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.graphics.Bitmap.createBitmap(Bitmap.java:468)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.graphics.Bitmap.createBitmap(Bitmap.java:435)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:340)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:590)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:564)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:425)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.content.res.Resources.loadDrawable(Resources.java:1709)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.view.View.<init>(View.java:1885)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.view.View.<init>(View.java:1834)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     at android.view.ViewGroup.<init>(ViewGroup.java:285)
02-25 11:34:13.772: ERROR/AndroidRuntime(3042):     ... 32 more

Of course i don’t have 2764800 byte png image, but i think its decoded size. So i thought that i had image handling problems and i checked and fixed my project in every detail to handle images correctly. I checked everything described in android-developers.blogspot.com/2009/01/avoiding-memory-leaks.html . I checked null drawables, i follow model reusability instructions, i changed loading methods described in : stackoverflow.com/questions/477572/android-strange-out-of-memory-issue/823966#823966.

Also i have few bitmaps to load from disk. My all layouts created by android xml layout files. I have plenty of bitmaps described in xml files also.

Then i saw that i have big static classes in application with memory analyzer. i freed that static properties by loading on demand and freeing after used. So finally i got this memory leak suspects in MAT;

Problem Suspect 1

3,043 instances of "java.lang.Class", loaded by "" occupy 871,304 (17.97%) bytes.

Biggest instances:
class com.ibm.icu4jni.util.Resources$DefaultTimeZones @ 0x4014c3b0 - 166,768 (3.44%) bytes.
class android.text.Html$HtmlParser @ 0x400fe448 - 126,592 (2.61%) bytes.
class com.google.googlenav.proto.GmmMessageTypes @ 0x4835d450 - 56,944 (1.17%) bytes.
class org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool @ 0x47caea20 - 51,872 (1.07%) bytes.
class org.apache.harmony.security.fortress.Services @ 0x4008c4d0 - 51,456 (1.06%) bytes.

Problem Suspect 2

8,721 instances of 'java.lang.String', loaded by 'system class loader' occupy 549,624 (11.33%) bytes. 

Keywords
java.lang.String

Problem Suspect 3

60 instances of "org.bouncycastle.jce.provider.X509CertificateObject", loaded by "system class loader" occupy 300,024 (10.76%) bytes. These instances are referenced from one instance of "java.util.Hashtable$HashtableEntry[]", loaded by "system class loader"

Keywords
org.bouncycastle.jce.provider.X509CertificateObject
java.util.Hashtable$HashtableEntry[]

This third one not occurs every time. Generally when i use memory manager in GalaxyTab.

My biggest Top-level Dominator Classes are these. http://www.matriks.mobi/arge/android/Screen%20shot%202011-02-25%20at%2012.19.08%20PM.png

I have just 2 or 3 activities live and the rest of them are suspended. I get this messages in components report. Of course this is not the explanation that i use just 1.5 MB of ram, because according to memory manager my application uses 48 MB of ram up from about 20 MB.

Possible Memory Waste
* Duplicate Strings*
Found 0 occurrences of char[] with at least 10 instances having identical content. Total size is 0 bytes.

i think thats not the thing that i want :) hprof file located in http://www.matriks.mobi/arge/android/android5706014442078310727.hprof.zip

I am guessing that i have problem with ActivityGroup class. At least i am keeping activities and activity ids in LocalActivityManager in stacks. But even if i don’t create new activities, and passing between loaded ones, memory increases.

I know this is not the way of searching for leaks, and possibly i have a code based problem causing this memory leaks. But any single idea that i should check will be very very welcome here, because i am kinda stuck here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

世界和平 2024-10-26 11:21:00

尝试在应用程序使用时跟踪内存分配

此外,保留对位图可绘制对象的引用可能会产生内存泄漏 。将 Drawable 添加到 View 时,会创建循环引用。因此,当您持有对 Bitmap 可绘制对象的引用时,它还持有对 View 的引用,并且该 View 永远不会被 GC 。

避免这种情况的最简单方法是从位图可绘制对象中提取位图并保存对其的引用,然后当活动重新启动/重新加载时,您可以从此位图创建新的位图可绘制对象。这是 Photostream 示例的工作原理(在最后描述):
更快的屏幕方向更改

Try tracking memory allocations while application is in use.

Also, holding references to Bitmap Drawables can produce memory leaks. When a Drawable is added to View, a circular reference is created. So when you hold a reference to Bitmap drawable, it further holds a reference to a View and this View can never be GCed.

The easiest way to avoid it is to extract a bitmap from a Bitmap Drawable and hold a reference to it, then when Activity is restarted/reloaded, you create new Bitmap Drawables from this bitmaps. This is how a Photostream example works (described at the end):
Faster screen orientation change

剑心龙吟 2024-10-26 11:21:00

您是否将此布局用于 ListView 的行?

Do you use this layout for the rows of a ListView?

红颜悴 2024-10-26 11:21:00

每次创建活动组时,我都会重置背景图像;

 background.setBackgroundResource(R.drawable.background); 

我删除了这个并将描述保留在 xml 中,所以问题解决了。该方法会导致内存泄漏。

I was resetting background image everytime activitygroup created by;

 background.setBackgroundResource(R.drawable.background); 

I removed this and left the description in xml, so problem solved. This method causes memory leaks.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文