title: converting data from surface View into Jpeg
body: <p>Hi i'm capturing frames from surface View and have Task to covert it to jpg and save to file. But i can`t release memory. After few seconds i have OutOfMemoryExc. Here id my Async:</p>
  
  <pre><code>    @Override
          protected Void doInBackground(byte[]... frames) {
  
              byte[] data = frames[0];
  
              int[] imagePixels = convertYUV420_NV21toRGB8888(data, mPreviewWidth, mPreviewHeight);
              Bitmap bitmapImage = Bitmap.createBitmap(imagePixels, mPreviewWidth, mPreviewHeight, Bitmap.Config.ARGB_8888);
              bitmapImage.recycle();
              ByteArrayOutputStream byteArrayOs = new ByteArrayOutputStream();
              bitmapImage.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOs);
  
              bitmapImage.recycle();
              System.gc();
              OutputStream os = null;
  
              boolean imageSaved = true;
  
              try {
                  os = new FileOutputStream(FileService.generateFrameFile());
                  os.write(byteArrayOs.toByteArray());
              } catch (Exception e) {
                  e.printStackTrace();
                  imageSaved = false;
              } finally {
                  try {
                      if(bitmapImage != null) {
                          bitmapImage.recycle();
                      }
                      if(byteArrayOs != null) {
                          byteArrayOs.close();
                      }
                      if (os != null) {
                          os.flush();
                          os.close();
                      }
                  } catch (Exception e) {
                      imageSaved = false;
                  }
              }
              mCallback.onTaskCompleted(imageSaved);
  
              return null;
          }
  </code></pre>