ringa_lee2017-04-17 15:50:42
android:largeHeap="true"
After the picture wall is loaded, it requires 90%+ of the memory. The official tutorial used by developer.android.com/training/displaying-bitmaps/process-bitmap.html also has a bitmap memory leak problem. The memory increment increases every time you enter and exit the activity. It is about 1%, and the maximum number of pictures loaded is almost the same! !
I suspect that Android itself is not good at handling bitmap issues
ringa_lee2017-04-17 15:50:42
Let’s not talk about whether the tool is ideal or not, how to reduce memory usage?
The usual way is to sample through Options.inSampleSize, which will cause a decrease in image quality, but it is effective.
Although there are related configs provided by universal-imageloader configuration, but after reading the source code, you will find that the default configurations will not shrink the image when it is smaller than the screen resolution. Therefore, if you have a mobile phone with a higher resolution, in most cases universal-imageloader will Process with inSampleSize=1, that is, no sampling. So my processing method is to modify it based on his source code and add several sampling dimensions. Even if the image is smaller than the current screen resolution, it can still be controlled. He conducts sampling. Compared with the original configuration, this method reduces the cost of memory usage (sampling size + 1 memory usage should be reduced by 75%). In theory, the picture effect will be worse, but in fact, although the resolution of mobile phones has been improving, the size is the same Between 4-6 inches, for thumbnails, this loss cannot be judged by the naked eye. High-quality pictures can be displayed in large pictures.
In addition, for imageloader, .bitmapConfig (Bitmap.Config.RGB_565) can also be reduced Memory usage is explained in the official documents.
In addition, you said that repeated entering and exiting the activity will cause this problem. You can try to manually recycle the images. I have not tried this combination of these frameworks. Try it yourself.
大家讲道理2017-04-17 15:50:42
It overflows after "repeatedly entering", there may be a memory leak.
You can dump the heap and see who holds the bitmap reference
阿神2017-04-17 15:50:42
"There are more than a hundred pictures in the activity"
Do you want to display them all? It must only show part of it.
Others will be displayed after sliding to the corresponding position
黄舟2017-04-17 15:50:42
Baidu: image-loader, there are many third-party jar packages for android, which are very easy to use, xutils, etc.
大家讲道理2017-04-17 15:50:42
Dynamic loading, only displays what you are currently displaying, and releases the corresponding bitmap if it is not needed
大家讲道理2017-04-17 15:50:42
If OOM overflows, it must be a leak in the java layer. Use MAT to analyze the reference situation.
android:largeHeap="true" is nothing more than delaying the emergence of OOM