我已經提到了更多關於我的問題。但是我還是無法解決我的問題,我無法預測爲什麼它會在特定的設備上發生,尤其是Galaxy S3。我也在其他設備上運行相同的應用程序,它工作正常。我發現使用eclipse MAT的內存泄漏。這正是我在我的應用程序上使用的圖像編輯類。我還沒有嘗試過bitmap.recyle(),因爲我通過了這個應用程序。 ImageEditView類用於在屏幕上顯示圖像。我已經通過使用下面的代碼片段加載了位圖。三星Galaxy S3中的位圖「OutOfMemoryError」
private Bitmap decodeAndDownsampleImageURI(Uri uri) {
Bitmap bitmap = null;
try {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
options.inPurgeable = true;
BufferedInputStream in = new BufferedInputStream(getContext().getContentResolver().openInputStream(uri));
BitmapFactory.decodeStream(in, null, options);
in.close();
int scale = 1;
if (options.outHeight > IMAGE_MAX_SIZE || options.outWidth > IMAGE_MAX_SIZE) {
scale = (int) Math.pow(
2,
(int) Math.round(Math.log(IMAGE_MAX_SIZE/(double) Math.max(options.outHeight, options.outWidth))
/Math.log(0.5)));
}
options = new BitmapFactory.Options();
options.inSampleSize = scale;
in = new BufferedInputStream(getContext().getContentResolver().openInputStream(uri));
bitmap = BitmapFactory.decodeStream(in, null, options);
in.close();
} catch (FileNotFoundException e) {
log.error(MyStyleApplication.hockeyAppLogMessage, e);
Log.e(TAG, "decodeAndDownsampleImageUri()", e);
} catch (Exception e) {
log.error(MyStyleApplication.hockeyAppLogMessage, e);
Log.e(TAG, "decodeAndDownsampleImageUri()", e);
}
return bitmap;
}
}
請人建議我一個更好的解決方案出來我的問題。
您需要清除位圖緩存並使用LRU緩存。作爲替代方案,您可以使用UniversalImageLoader。祝你好運 –
專家請參考後續報告,並建議我一個更好的解決方案。由「dalvik.system.PathClassLoader @ 0x41be12d0」加載的「com.newvisioninteractive.android.mystyle.widget.ImageEditView」的一個實例佔據了50,538,632(73.52%)個字節。內存在由「dalvik.system.PathClassLoader @ 0x41be12d0」加載的「com.newvisioninteractive.android.mystyle.widget.ImageEditView」的一個實例中累積。 關鍵字 dalvik.system.PathClassLoader @ 0x41be12d0 com.newvisioninteractive.android.mystyle.widget.ImageEditView – chain
@ Yume117感謝您的建議。我一直在嘗試你的方法。如果你粘貼一些例子,這對我來說很容易實現。 – chain