A
A
Alexander2014-04-26 20:14:07
Java
Alexander, 2014-04-26 20:14:07

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);
}

How to remove an object from memory?
At the moment the only thing on my mind is to put (user = null) in onDestroy;

Answer the question

In order to leave comments, you need to log in

3 answer(s)
F
FoxInSox, 2014-04-26
@FoxInSox

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;

S
svd71, 2014-04-26
@svd71

@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.

S
Sergey, 2015-07-09
@stweet

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 question

Ask a Question

731 491 924 answers to any question