In my Android application, I need to get images from the server and cache them in heap memory.
Upon receipt of the request, the server first encodes byte[] in Base64String and returns this string. And while rendering in ImageView , the Android application decodes Base64String back to byte[] , creates a Bitmap and puts it in ImageView .
Since everything is in the cache, it is likely that the application will at some point go out of memory and is critically critical.
To prevent a memory situation, in my application I defined security (for example, 5 MB). If at any time the available memory falls below this protective quantum , the user will need to mark some images as candidates for deletion. In addition, the application will display the estimated memory that will be released after the removal of the selected items.
Bitmap been redesigned as soon as the user moves away from the image, so Bitmap does not effectively hold memory until we leave.
In a specific test, I upload 55 images, and my heap grows from 16 MB to 42 MB . This means that 55 images occupy 26 MB . After I cleaned them, the heap is compressed to 16 MB .
But, when I take the cumulative sum of the lengths of all Base64String , it comes to 11983840 . And if I consider one character as 1 byte , 11983840 bytes makes 11.4 MB
The problem is that the total amount of Base64String lengths is the only measure available to me that allows the user to know how much memory can be released at his option.
I also read the following question, which mentions that for every 3 Bytes source data, Base64String will have 4 Characters .
Calculation of base length64?
The question is, Base64String one character in Base64String contain the number of bytes? 1, 2 or more
If 1 character is 1 byte , and in my test the heap grows and shrinks 26 MB . Then why is the total length of Base64String only 11.4 MB ?
Update

This means 1 byte per character.

The default character set is UTF-8