2011-08-10 3 views
1

このブロックが実行されるたびに、DDMSで使用されるメモリ%が毎回2%ずつ増加し、ビットマップ割り当てで最終的にクラッシュするまでのメモリの問題があります。Androidでのメモリトラッキング/リーク

Uri U = null; 

    try { 
     String state = Environment.getExternalStorageState(); 
     if (Environment.MEDIA_MOUNTED.equals(state)) { 
      // We can read and write the media 
      File path = this.getExternalFilesDir(Environment.DIRECTORY_PICTURES); 
      File file = new File(path, "image.jpg"); 
      path.mkdirs(); 

      FileOutputStream Os = new FileOutputStream(file); 
      getFullResFilteredImage().compress(Bitmap.CompressFormat.JPEG, 80, Os); 

      Os.flush(); 
      Os.close(); 
      Os = null; 

      U = Uri.fromFile(file); 
      file.deleteOnExit(); 
      file = null; 
     } else { 
      Toast toast = Toast.makeText(PrintLabActivity.this.getApplicationContext(), 
        PrintLabActivity.this.getResources().getString(R.string.sd_image_error), Toast.LENGTH_SHORT); 
      toast.show(); 
      return; 
     } 

    } catch (Exception e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

    Intent i = new Intent(Intent.ACTION_SEND); 
    i.setType("image/jpg"); 
    i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 
    i.putExtra(Intent.EXTRA_STREAM, U); 

    i.putExtra(Intent.EXTRA_SUBJECT, this.getResources().getString(R.string.email_subject)); 
    String message = this.getResources().getString(R.string.email_message, PNBApplication.MARKETPLACE_URL, PNBApplication.MARKETPLACE_URL); 
    i.putExtra(Intent.EXTRA_TEXT , Html.fromHtml(message)); 
    U = null; 

    this.startActivity(Intent.createChooser(i,"Send Image To:")); 

このコードには、毎回何が割り当てられているのかを示す方法はありません。

答えて

0

BitmapFactory.Options.inSampleSizeを使用すると、ビットマップを作成するときのメモリ消費を減らすことができます。

さらに詳しい回答については、getFullResFilteredImage()メソッドを投稿してください。

+0

'getFullResFilteredImage()'は実際には割り当てなしで元のフルサイズのビットマップへの参照をカメラから返します。この場合でも2%のジャンプが発生します。 – Affian