What I'm essentially doing is adding collections to a collection. The app
will use maybe a few elements in a nested collection for a short while then
never use that collection again.
Collections.add is defined as follows:
"Ensures that this collection contains the specified element (optional
operation). Returns true if this collection changed as a result of the
call. (Returns false if this collection does not permit duplicates and
already contains the specified element.)"
So lets assume your collection does not allow dups, e.g. HashMap
If the element is already in the Collection, it does nothing.
So lets us say you had collection cbig and clittle and added all the
elements of clittle to cbig. The only changes to cbig would be for
the elements that cbig did not have already. If you then discarded
clittle, the clittle object itself would become candidates for gc, but
none of its members would because cbig has pointers to all of them.
Now lets assume your collection did allow dups, e.g. ArrayList. Then
you have TWO pointers to the duplicated elements. There's one object,
but two pointers to it. ArrayList also allows duplicates that are not
identical, e.g. two objects that compare equal with a custom equals
method. In that case you have two objects and two pointers. Both will
held in RAM.