У меня есть вопрос о утечке памяти. < /p> У меня есть два класса - первый: < /p> [code]public class Utility { private static Utility instance = null; private UpdateListener listener;
// Make it a Singleton class private Utility() {}
public static Utility getInstance() { if (instance == null) instance = new Utility(); return instance; }
public void setListener(UpdateListener listener) { this.listener = listener; }
// Long running background thread public void startNewTread() { new Thread (new Runnable() { @Override public void run() { try { Thread.sleep(1000 * 10);
// Listener interface public interface UpdateListener { public void onUpdate(); } } < /code> Второй класс: < /p> public class ListenerLeak extends AppCompatActivity {
//Setting the listener Utility.getInstance().setListener(new Utility.UpdateListener() { @Override public void onUpdate() { Log.d("ListenerLeak", "Something is updated!"); } });
//Starting a background thread Utility.getInstance().startNewTread(); }
@Override protected void onDestroy() { super.onDestroy(); } } < /code> В этой деятельности. May New Utility.updateListener [/code] создать утечку памяти? Может ли деятельность быть живой?