Reputation: 3997
I am developing an android image capture application using opencv library(face-detection sample). My aim is to capture 5 images and send it to my webservice. After capturing image, convert the Bitmap image into base64 string and store into string[]. Finally I send this string[] to web service. This application working in my emulator. But when I check with my android tablet it throws "Grow heap (frag case) to 7.827MB for 1228816-byte allocation" exception and exit the application. After searching in the internet I found some of the links regarding this.
link-1: Android grow heap frag case
link-2: how can I clear growing heap?
But they didn't tell what I'll do If the problem exist. After saw some links, I think this may because of memory leak. But I don't know what to do. As I am new to the android, Can you give me some suggestions regarding this would be great.
I have attached my log file in the following link. http://pastebin.com/82VxhBmz
Upvotes: 0
Views: 4052
Reputation: 838
The hip growth in case of camera use is most likely due to the preview camera size. Hit that might help you solve the issue (when implementing SurfaceHolder.Callback):
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
Camera.Parameters parameters = camera.getParameters();
//get all supported sizes for the camera
List<Camera.Size> sizes = parameters.getSupportedPreviewSizes();
//make sure you select the smallest size (resolution), which is first in the list
Camera.Size selected = sizes.get(0);
//add the selected size
parameters.setPreviewSize(selected.width, selected.height);
//set the parameters
camera.setParameters(parameters);
camera.startPreview();
}`
Upvotes: 1
Reputation: 535
The problem which you are facing is mainly because of base64 which converts image to string.
when image with high size @ for example when you click image from camera it is always more in MB which when converted to string will use more memory. So when you have clicked many images, the string size will grow your memory size and will force android to destroy your application since Android destroy application which uses more memory when it is lacking in memory point of view.
So to upload multiple image to server use different method for Example refer to the following question where I had given answer how the user can upload images to server.
Android upload image from gallery to server
Upvotes: 1