OutOfMemory exception when loading bitmap from external storage

前端 未结 13 1705
广开言路
广开言路 2020-11-29 06:52

In my application I load a couple of images from JPEG and PNG files. When I place all those files into assets directory and load it in this way, everything is ok:

         


        
13条回答
  •  执笔经年
    2020-11-29 07:14

    You must not depends on the GC to recycle your bitmap memory. You must clearly recycle the bitmap when it is not needed.

    See the Bitmap method:

    void recycle() Free up the memory associated with this bitmap's pixels, and mark the bitmap as "dead", meaning it will throw an exception if getPixels() or setPixels() is called, and will draw nothing.

提交回复
热议问题