마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

bitmap recycle 재사용 오류 문제입니다...

0 추천
public static void starter(){ 
File file = new File(path); 
galleryIda = new ArrayList<Bitmap>(); 
String str = null; 
int num = 0; 

String[] flist = file.list(); 
if(flist != null) 
Log.i("tag","파일갯수"+(flist.length)); 
int imgCount = flist.length; 
if ( file.listFiles().length > 0 ) 
for ( File f : file.listFiles() ) { 
str = f.getName();  // 파일 이름 얻어오기 
//map[num] = BitmapFactory.decodeFile(path+str,options); 
try { 
if (!((path+str).matches(".*jpg.*") 
||(path+str).matches(".*gif.*") 
||(path+str).matches(".*png.*"))) continue; 
Bitmap map = loadBitmap(context,path+str); 
Log.i("tag","...path : " + (path+str)); 
galleryIda.add(map); 
if (map != null && !map.isRecycled()) 
            { 
map.recycle(); 
map = null; 
                System.gc(); 
            } 

} catch (OutOfMemoryError e) { 
// TODO Auto-generated catch block 
e.printStackTrace(); 
} catch (Exception e) { 
// TODO Auto-generated catch block 
e.printStackTrace(); 
} 
num++; 
} 
Log.i("tag","done"); 

} 




특정디렉터리에 있는 사진파일만 받아오는데 120M이상 받아오면 에러가 나더라구요 그래서 위와 같이 
if (map != null && !map.isRecycled()) 
            { 
map.recycle(); 
map = null; 
                System.gc(); 
            } 
추가했습니다. 
main activity 에서 위와 같은 소스 진행이 됩니다. 그리고 galleryIda에 있는 리스트를 adapterviewflipper에 붙이는 소스인데요 마지막에 done까지 확인되는데 이후에 activity가 나올때 

07-25 14:56:56.319: E/AndroidRuntime(21270): java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@42aa61d0 
  
에러가 나옵니다..... 

사진하나하나받아오는것은 loadBitmap에서 제어가 가능했는데... 재사용에러는 도무지 감이 안잡히네요 ㅠㅠ 

혹시 비슷한 경험 있으시면 도움 부탁드립니다!!!

익명사용자 님이 2014년 7월 25일 질문

1개의 답변

0 추천
http://helloworld.naver.com/helloworld/539525

링크 글을 꼼꼼하게 읽어보신다면 도움이 되실듯 싶네요
Gradler (109,780 포인트) 님이 2014년 7월 25일 답변
...