나는 항상 OutOfMemory
예외가 발생합니다.안드로이드 응용 프로그램 캐시 메모리
서버에서 내 응용 프로그램으로 다운로드 한 비트 맵 용량이 이미 캐시 메모리를 초과했다는 것을 알고 있습니다.
그러나 Maximum Cache Memory of my application I can stored (images)
의 양은 어느 정도입니까? 알고
사람,
말해주십시오감사, 문서에서
나는 항상 OutOfMemory
예외가 발생합니다.안드로이드 응용 프로그램 캐시 메모리
서버에서 내 응용 프로그램으로 다운로드 한 비트 맵 용량이 이미 캐시 메모리를 초과했다는 것을 알고 있습니다.
그러나 Maximum Cache Memory of my application I can stored (images)
의 양은 어느 정도입니까? 알고
사람,
말해주십시오감사, 문서에서
: 일반적으로 시스템 자원을 제한 한
모바일 장치. Android 장치는 하나의 응용 프로그램에서 사용할 수있는 메모리가 16MB 정도일 수 있습니다. Android 호환성 정의 문서 (CDD), 섹션 3.7. 가상 컴퓨터 호환성은 다양한 화면 크기 및 밀도에 대해 응용 프로그램 메모리 인 최소 을 제공합니다. 응용 프로그램은이 최소 메모리 크기 인 한계를 충족하도록 최적화되어야합니다. 그러나 많은 장치가 더 높은 제한으로 구성됩니다. 비트 맵은 특히 풍부한 이미지의 경우 많은 메모리를 사용합니다. 사진이 좋습니다. 예를 들어 Galaxy Nexus의 카메라는 사진을 최대 2592x1936 픽셀 (5 메가 픽셀)까지 사용합니다. 비트 맵 구성이 ARGB_8888 (Android 2.3 이후의 기본값) 인 경우이 이미지를 메모리에로드하면 약 012MB의 메모리가 소요됩니다 ( (2592 * 1936 * 4 바이트)). 기기의 앱당 한도가 즉시 소진됩니다. .
이며 앱별 한도는 기기마다 다르지만 16-25 MB 정도라고 생각합니다.
어떻게해야합니까? 파일에서 이미지를 읽고 난 문서에서 기능을 변경
을 :
먼저이 디스크에 이미지를 저장해야합니다, 당신이 좋아하는 어떤 이미지 뷰를 할당 한 다음 디코딩하고 다음 기능을 사용하여 리소스 폴더가 아닙니다.
public static int calculateInSampleSize(
BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
final int halfHeight = height/2;
final int halfWidth = width/2;
// Calculate the largest inSampleSize value that is a power of 2 and keeps both
// height and width larger than the requested height and width.
while ((halfHeight/inSampleSize) > reqHeight
&& (halfWidth/inSampleSize) > reqWidth) {
inSampleSize *= 2;
}
}
return inSampleSize;
}
public static Bitmap decodeSampledBitmapFromFile(String filePath,int reqWidth, int reqHeight) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(filePath, options);
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeFile(filePath, options);
}
그냥 decodeSampledBitmapFromFile(String filePath,int reqWidth, int reqHeight)
으로 전화하십시오.
참조 : 그들은 단지 문제의 대부분 알아서
Local image caching solution for Android: Square Picasso vs Universal Image Loader
:
Displaying Bitmaps Efficiently
또 다른 옵션에서 비교보기를 위해, 이미지 다운 로더 라이브러리를 사용하고 있습니다.
시도해주세요. http://stackoverflow.com/questions/15761679/memory-cache-in-android –
https://developer.android.com/tools/debugging/debugging-memory.html을 보았습니까? 이 페이지는 매우 유익합니다. –
및 https://developer.android를 참조하십시오.co.kr/training/articles/memory.html # 문제 해결을위한 메모리 제한 –