0

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

Community
  • 1
  • 1
Manoj
  • 3,947
  • 9
  • 46
  • 84
  • 1
    http://stackoverflow.com/questions/477572/android-strange-out-of-memory-issue-while-loading-an-image-to-a-bitmap-object see this link – Zombie Dec 17 '12 at 09:34
  • thanks. I will check it. I have attached my log file. – Manoj Dec 18 '12 at 08:12

2 Answers2

1

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

Community
  • 1
  • 1
Parth Dani
  • 535
  • 4
  • 19
  • Thanks for your answer. I will try what you suggest and let you know the result. – Manoj Dec 17 '12 at 10:24
  • Sure manoj...But if my answer has helped you please accept it so that it will help others as well in the future. – Parth Dani Dec 17 '12 at 11:03
  • The example says upload file from Gallery and using HTTP Post. But I didn't store file in Gallery and also I want to send the image to already existing soap web service(server side java) and also my image size is less than 1MB((i.e)22 kb) and I am taking only 5 images. so what may be the problem? – Manoj Dec 18 '12 at 04:41
  • I have attached my log file. – Manoj Dec 18 '12 at 07:39
  • Try to upload image from other method i.e. SOAP/KSOAP method.There are libraries out there which will help you to upload file and images to the server. When base64 tries to convert image into string it uses more memory.So the heap size is increased by the device and after the limitation of heap size it starts destroying all the application which are using high memory. – Parth Dani Dec 18 '12 at 09:29
1

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();

}`
ViksaaSkool
  • 738
  • 4
  • 18