When a ListView is used to load a large image, a memory overflow is encountered and crashes.
But the use of LRUCache was supposed to solve the problem. However, there is a memory overflow condition found. Troubled for a long time
In addition, after the picture has been downloaded and saved locally, it is found that when a large number of images are read, the use of LRUCache does not cause a crash due to memory leaks.
Finally through the view log found that in the network loading time to eat memory, with the continuous generation of threads to download pictures, can see the virtual machine to free up memory when the basic function of releasing up to more than 10 K per time, memory is almost full ...
While loading the local image, memory release is indeed quite timely, about 4M each time, so of course there will be no memory leaks ... Where does the problem occur?
Consider the possible factors: 1 Too many threads open.
But loading the local picture is also the opening of a new thread ... But it didn't crash.
2 Downloads too many temporary bitmap that have failed to release the cause?
But after the network loaded successfully I also put the download bitmap in the LRUCache, ah, supposedly he should be in excess of the given laughter to help me free memory ah ... Why is it? Is there a place where there is a blockage, and this place is constantly stacking bytes into memory? So I found the place to download the pictures.
Conn.connect ();
Bitmap = Bitmapfactory.decodestream (is,null,bmpfactoryoptions);
The problem should be here, when too many threads are being opened to download images, the download process buffers too many byte[] and waits for the data to come in their own threads. In this way, the virtual machine does not release this data, and multiple threads are blocked, causing a memory overflow. And that leads to the problem.
To avoid this problem, there are two solution ideas, 1 less open a few threads 2 pictures not too big.
So I don't know if it's right .... Yes, I think so.