安卓内存泄露? [英] Android memory leak?

查看:35
本文介绍了安卓内存泄露?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为我的 android 应用程序正在泄漏内存.不过,我不确定这就是问题所在.

I think my android app is leaking memory. I'm not absolutely sure that this is the problem though.

应用程序在打开时经常崩溃,并且 logcat 在尝试加载位图图像时显示内存不足"异常.

Every so often the app crashes when opening, and logcat shows an "out of memory" exception trying to load a bitmap image.

崩溃后,我重新打开应用程序,它运行良好.Logcat 显示大量gc",并且每隔一段时间 JIT 表都会向上调整大小,直到应用程序因内存不足错误而崩溃.

After crashing, I re-open the app and it works fine. Logcat shows lots of "gc"s and every once in a while the JIT table is resized upwards, never downwards until the app crashes with the out of memory error.

这听起来像内存泄漏吗?如果是这样,我该如何定位和关闭泄漏点.

Does this sound like a memory leak? If so, how do I go about locating and closing the leak.

这是我的应用程序的 adb shell meminfo.

Here is my adb shell meminfo for my app.

** MEMINFO in pid 2691 [com.example.deepcliff] **
                    native   dalvik    other    total
            size:    23264     8839      N/A    32103
       allocated:    12503     3826      N/A    16329
            free:      168     5013      N/A     5181
           (Pss):     2512     1395    13815    17722
  (shared dirty):     2088     1844     5008     8940
    (priv dirty):     2412      224    11316    13952

 Objects
           Views:        0        ViewRoots:        0
     AppContexts:        0       Activities:        0
          Assets:        2    AssetManagers:        2
   Local Binders:       55    Proxy Binders:       13
Death Recipients:        1
 OpenSSL Sockets:        0

 SQL
               heap:      129         MEMORY_USED:      129
 PAGECACHE_OVERFLOW:        9         MALLOC_SIZE:       50

 DATABASES
      pgsz     dbsz   Lookaside(b)  Dbname
         1       14             10  webview.db
         1        6             18  webviewCache.db

 Asset Allocations
    zip:/data/app/com.example.deepcliff-2.apk:/resources.arsc: 17K

推荐答案

这里有几篇文章和帖子,可能会帮助您走上正轨:

Here are a couple of articles and posts, which probably help you to get on the right track:

Allocation tracker,Android SDK 自带的非常有用.阅读 Romain Guy 的文章.它帮助我追踪了非常讨厌的泄漏.它还可以帮助您编写更好的软件.例如.我学会了创建更少的对象,使用更多的 StringBuilder,并缓存更多:
哪些 Android 工具和方法最适合查找内存/资源泄漏?

Allocation tracker, which comes with Android SDK is very useful. Read Romain Guy's articles. It helped me to track down pretty nasty leaks. It also helps you to write better software. E.g. I learned to create less objects, use more StringBuilder, and cache a lot more:
What Android tools and methods work best to find memory/resource leaks?

有时您的应用程序非常混乱,您必须从整体上重新设计它.以下是对此的官方提示(我最喜欢的是避免创建不必要的对象):
http://developer.android.com/guide/practices/design/performance.html

Sometimes your app is just so messed up that you have to re-design it in the whole. Here are official, good hints for that (my favourite is the Avoid Creating Unnecessary Objects):
http://developer.android.com/guide/practices/design/performance.html


这是一篇关于解决记忆问题的优秀文章:
http://ttlnews.blogspot.com/2010/01/attacking-memory-problems-on-android.html

关于避免内存泄漏的官方文章:
http://android-developers.blogspot.co.uk/2009/01/avoiding-memory-leaks.html

Official article about avoiding memory leaks:
http://android-developers.blogspot.co.uk/2009/01/avoiding-memory-leaks.html

另请阅读:检查 android 内存泄漏的工具


其他人已经指出了位图.这是一篇描述该问题的文章:http://zrgiu.com/blog/2011/01/android-bitmaps-and-out-of-memory-errors/


Others already pointed about bitmaps. Here's an article describing the issue: http://zrgiu.com/blog/2011/01/android-bitmaps-and-out-of-memory-errors/

这篇关于安卓内存泄露?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆