2014-02-07 4 views
0

나는이 내 모든 유용한 방법 유지 Util라는 이름의 클래스 (등, 비트 맵을 회전 음악을 다운로드, 음악을 연주 확장 다운로드 이미지를, ...)Android 활동이 삭제되었지만 가비지 수집되지 않았습니까?

public class Util{ 
    public static Bitmap downloadImage(Context context, String url) throws SocketException { 
     // Implementation 
    } 

    public static Bitmap rotateBitmap(Bitmap bitmap, float degree) { 
     // Implementation 
    } 

    // And other stuff 
    public static int getApplicationVersion(Context context){ 
     // Impl... 
    } 
} 

나는 두 개 이상의 활동과 I가있는 경우 각각의 활동에서 유용한 메소드를 호출하면 메모리 누수가 발생합니까? Util 클래스는 활동 간 참조를 보유하는 "다리"와 같을까요?

public Activity_A extends Activity{ 
    @Override 
    protected void onCreate(Bundle bundle){ 
     Bitmap bitmap = Util.downloadImage(this, "http://static.asd...."); 
    } 
} 

public Activity_B extends Activity{ 
    @Override 
    protected void onCreate(Bundle bundle){ 
     Bitmap bitmap = Util.downloadImage(this, "http://something"); 
     bitmap = Util.rotateBitmap(bitmap, 90f); 
    } 
} 

또는 조각에 전화 :

public class MyFragment extends Fragment{ 
    @Override 
    protected void onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){ 
     // inflating... 


     Util.playBackgroundMusic(getActivity(), Constants.MUSIC_1); 

     Log.i("APP", "Application version is: " + Util.getApplicationVersion(getActivity()); 
    } 
} 

이 메모리 누수가 발생할 수 있습니까? 나는 매우 혼란 스럽다 ...

+0

한마디로, 예. 활동의 어떤 것에도 정적 참조를 두지 마십시오. 비트 맵은 활동 컨텍스트에 바인딩됩니다. 이것을 읽으십시오. http://www.curious-creature.org/2008/12/18/avoid-memory-leaks-on-android/ – Simon

+0

@ Simon은 사실이 아닙니다. Romain Guy는 Drawable이 소유하고있는 Activity, Bitmap 그러한 참조를 가지고 있으며 매우 안전하게 캐시 될 수 있습니다. – Kai

답변

0

정적 인 Util 클래스 내의 활동에 대한 참조를 가지고 있다면, 그것이 끝난 후에도 가비지 수집을 방지 할 수 있기 때문에 문제가 될 것이라고 생각한다.

하지만 귀하의 경우에는 메모리 누수 문제가 발생하지 않습니다.

관련 문제