버튼에 이미지를 입히기 위해 ResourceLoader 클래스를 만들어 하나로 뭉쳐져 있는 비트맵 정보를 불러오게 만들었습니다.

BitmapFactory를 사용하면 생성되는 bitmap을 recycle()해줘야 한다고 들었는데, 제 짧은 식견으로는 어떻게 해야 할지 당췌 감이 안잡힙니다.

코드를 보고 조언을 해주세요.


public Bitmap GetBitmapImage(int i)
 {
  Bitmap retBitmap = null;
  byte[] BinaryData = null;
  byte[] DecompressedData = null;
  byte[] CompressedData = null;
  int DecompressedSize;
  
  BinaryData = GetCompressedImage(i);
  
  ByteArrayInputStream bais = new ByteArrayInputStream(BinaryData);
  DecompressImage ImageInfo = new DecompressImage(bais);
  CompressedData = new byte[(int)ImageInfo.comSize];
  try {
   bais.read(CompressedData);
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  
  DecompressedSize = m_pkHeader.kPosInfo[i].iWidth * m_pkHeader.kPosInfo[i].iHeight * 4 + 54 + 2;  //32비트 이미지라서 4를 곱합 헤더 54바이트 2는 자꾸 모자라길래...
  DecompressedData = Unzip(CompressedData, DecompressedSize);
  
//여기서 OOM 익셉션이 발생합니다.
  retBitmap = BitmapFactory.decodeByteArray(DecompressedData, 0, DecompressedSize);
  
//  if(retBitmap != null)
//  {
//   retBitmap = Bitmap.createBitmap(retBitmap, 0, 0, (int)ImageInfo.bmWidth, (int)ImageInfo.bmHeight);
//  }
  return retBitmap;
 }

public Drawable GetDrawableImage(int i)
 {
    return new BitmapDrawable(GetBitmapImage(i));
 }



이런식으로 만들어져 있고,

불러쓰는 형식은

Button myButton = (Button) find....;
myButton.SetBackgroundDrawable(loader.GetDrawableImage(5));

이렇게 해주고 있습니다. 이렇게 된 코드를 어디에서 비트맵 해제를 해줘야 할 지 모르겠습니다.

도움을 주세요 ㅠㅠ