Robert Uomini
- Forum posts: 10
Apr 13, 2012, 4:21:15 AM via Website
Apr 13, 2012 4:21:15 AM via Website
Having another memory problem which, unfortunately, can't be solved this time by saving to disk.
In the above code, the String encodedContent seems to be taking twice as much space as expected. For example, it grows by at most BUFSIZE (64 K with each iteration of the loop, but when it has grown to 500 KB, the VM is allocating memory for 1 MB. When encodedContent is 900 KB in size, the VM is allocating 1.8 MB, etc. Anyone know why encodedContent should take twice it's needed memory and what to do about it?
1int byteCount;
2 byte[] tmp = new byte[BUFSIZE];
3 encodedContent = "";
4
5 do {
6 byteCount = is.read(tmp, 0, BUFSIZE);
7 if (byteCount == -1) break;
8 encodedContent += Base64.encodeToString(tmp, 0, byteCount, Base64.NO_WRAP);
9 } while (byteCount != -1);
2 byte[] tmp = new byte[BUFSIZE];
3 encodedContent = "";
4
5 do {
6 byteCount = is.read(tmp, 0, BUFSIZE);
7 if (byteCount == -1) break;
8 encodedContent += Base64.encodeToString(tmp, 0, byteCount, Base64.NO_WRAP);
9 } while (byteCount != -1);
In the above code, the String encodedContent seems to be taking twice as much space as expected. For example, it grows by at most BUFSIZE (64 K with each iteration of the loop, but when it has grown to 500 KB, the VM is allocating memory for 1 MB. When encodedContent is 900 KB in size, the VM is allocating 1.8 MB, etc. Anyone know why encodedContent should take twice it's needed memory and what to do about it?
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.