我已经提到了更多关于我的问题。但是我还是无法解决我的问题,我无法预测为什么它会在特定的设备上发生,尤其是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