10-12 10:47:58.208: ERROR/AndroidRuntime(279): Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class <unknown>
10-12 10:47:58.208: ERROR/AndroidRuntime(279): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
怎么处理图片的加载问题???用完之后就立马释放????
求解决问题???

解决方案 »

  1.   

    你的bitmap在activity退出时调用了 recycl()函数了吗?这是个老问题了,你给bitmap分配了超过8M的内存。 网上有许多解决办法。但最好还是将你的图片改小。
      

  2.   

    android系统中读取位图Bitmap时.分给虚拟机中图片的堆栈大小只有8M。所以不管是如何调用的图片,太多太大虚拟机肯定会报那个错误。public void distoryBitmap(){
    if(null!=bmb&&!bmb.isRecycled())
    bmb.recycle();
    }
    最好的解决方案是在自定义的View中添加一个init()初始化方法的头部调用.或者在构造函数的顶部调用:public class GifView extends View implements Runnable {
    private Bitmap bmb; public GifView(Context context, InputStream inputStream) {
    super(context);
    distoryBitmap();
    bmb = BitmapFactory.decodeStream(is);
    }
    }
      

  3.   

    sdk doc: /resources/articles/avoiding-memory-leaks.htmlIn summary, to avoid context-related memory leaks, remember the following:    * Do not keep long-lived references to a context-activity (a reference to an activity should have the same life cycle as the activity itself)
        * Try using the context-application instead of a context-activity
        * Avoid non-static inner classes in an activity if you don't control their life cycle, use a static inner class and make a weak reference to the activity inside. The solution to this issue is to use a static inner class with a WeakReference to the outer class, as done in ViewRoot and its W inner class for instance
        * A garbage collector is not an insurance against memory leaks目前一般尽量避免oom的方法有:1,设置options
    2,使用软引用
    3,手动recycle
    4,设置Bitmap RGB_565
    5,设置系统堆大小
      

  4.   

    Do not keep long-lived references to a context-activity (a reference to an activity should have the same life cycle as the activity itself)
    这个也许就能解决lz的问题了。