以下の例のメモリリーク。
1.SpeedHelper.java:
public class SpeedHelper {
interface Listener {
void OnSelected(String entry);
}
static Listener sListener;
static void setListener(Listener listener) {
sListener = listener;
}
static Listener getListener() {
return sListener;
}
static void clearListener() {
sListener = null;
}
}
2.CallSpeed.java
public class CallSpeed {
protected void speed() {
SpeedHelper.Listener litener = SpeedHelper.getListener();
if (litener != null) {
litener.OnSelected("mEntry");
}
}
}
3.MainActivity.java
public class MainActivity extends Activity {
private CallSpeed callspeed;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SpeedHelper.setListener(mCallSpeedListener);
callspeed = new CallSpeed();
callspeed.speed();
}
private SpeedHelper.Listener mCallSpeedListener = new SpeedHelper.Listener() {
@Override
public void OnSelected(String entry) {
Toast.makeText(getApplicationContext(), entry, Toast.LENGTH_SHORT).show();
}
};
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
SpeedHelper.clearListener();
}
}
「sListener」のメモリリークを回避するにはどうすればよいですか?