Answer the question
In order to leave comments, you need to log in
How to remove an object from memory, Java?
There is a static reference to the UserInterface class (object) public static UserInterface user;
After the Android application was closed in this case (onDestroy method), the reference was stored in memory as the object itself, because of this, the condition did not work in the onCreate method
if(user == null)
{
user = new UserInterface(this, getApplicationInfo());
user.setListener(this);
}
Answer the question
In order to leave comments, you need to log in
No way. This is the job of a garbage collector. To let him know that the object can be erased from memory, you need to remove all references to it. Those.:user = null;
@oxInSox was a little tricky. The fact is that nulling the referential integrity will not guarantee the destruction of the object. After that, it is desirable to make the garbage collector work
. This is especially important for the objects of the heirs of threads and early balls.
Also asked a similar question. Previously, I wrote on AS (Flash) there with handlers tight, you have to follow it yourself. Now in JAVA I faced a similar problem.
Example:
There is a certain list of checkboxes, I subscribe to changing the state of each of them. The list itself forms a model from a file selected by the user.
Question:
Is it important to unsubscribe from each checkbox in case of updating the list, or is it enough just to delete the checkbox itself?
Simply, the list of fields is not small and the desire to optimize is constantly distracting. Thanks in advance!
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question