如果我多次关闭并打开我的应用程序,我最终会出现内存不足错误,这是否意味着我有内存泄漏?
我有一个应用程序,可以让用户从 SD 卡中选取图像,然后应用程序处理该图像。我将图像缩小到可用虚拟机内存的 1/5,并且在 onDestroy() 调用中为每个位图调用 recycle(),如果我多次关闭并打开应用程序,我仍然会出现内存不足错误。
I have an app which let users to pick an image from sd card and then app process the image. I am downsizing images to 1/5 of avialable vm memory and i do call recycle() for every bitmap in onDestroy() call and i still get out of memory error if i close and open my app multiple times.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Android 中存在多种内存泄漏情况。追踪它们的一种方法是使用 Traceview 工具 http://developer .android.com/guide/developing/debugging/debugging-tracing.html。
有关常见 Android 内存泄漏问题的更多信息,请参阅 http:// /android-developers.blogspot.co.uk/2009/01/avoiding-memory-leaks.html
There are various memory leak scenarios in Android. One way to track them down is to use the Traceview tool http://developer.android.com/guide/developing/debugging/debugging-tracing.html.
For more info on common Android memory leak problems see http://android-developers.blogspot.co.uk/2009/01/avoiding-memory-leaks.html
请注意,当您完成应用程序的最后一个
Activity
时,应用程序的 Java 进程可能(在大多数情况下)仍处于活动状态,这意味着当您再次“启动”应用程序时,所有静态内容仍然处于活动状态。您是否在静态字段中存储任何重物?另请注意,根据
Activity
生命周期,不保证调用onDestroy()
。但是我不认为这是相关的,因为当您(相对于操作系统)关闭Activity
(通过按“后退”按钮或通过调用finish()
代码),然后操作系统总是调用onDestroy()
。一般来说,在没有看到代码的情况下很难说出会发生什么。
Note that when you finish the last
Activity
of the app the Java process of your app may (in most cases will) be alive meaning all static stuff is still alive when you "start" the app again. Do you store any heavy objects in static fields?Also note that according to the
Activity
life-cycle theonDestroy()
is not guaranteed to be called. However I don't think this is related, because when you (versus the OS) close theActivity
(either by pressing 'Back' button or by callingfinish()
from the code) then OS always callsonDestroy()
.In general, without seeing the code it is difficult to say what happens.