Java Collections and Garbage Collector
Posted
by Anth0
on Stack Overflow
See other posts from Stack Overflow
or by Anth0
Published on 2010-01-18T14:47:59Z
Indexed on
2010/03/08
15:06 UTC
Read the original article
Hit count: 421
A little question regarding performance in a Java web app.
Let's assume I have a List<Rubrique>
listRubriques
with ten Rubrique
objects.
A Rubrique
contains one list of products (List<product>
listProducts
) and one list of clients (List<Client>
listClients
).
What exactly happens in memory if I do this:
listRubriques.clear(); listRubriques = null;
My point of view would be that, since listRubriques
is empty, all my objects previously referenced by this list (including listProducts
and listClients
) will be garbage collected pretty soon. But since Collection in Java are a little bit tricky and since I have quite performance issues with my app i'm asking the question :)
edit : let's assume now that my Client object contains a List<Client>
. Therefore, I have kind of a circular reference between my objects. What would happen then if my listRubrique
is set to null
? This time, my point of view would be that my Client objects will become "unreachable" and might create a memory leak?
© Stack Overflow or respective owner