Question

I'm using the HPPC package and I had a question. In the API it says the following for the DoubleOpenHashSet.clear() method:

Removes all elements from this collection.
Does not release internal buffers.

What exactly does the second line imply? Does that mean that the cleared elements won't be garbage collected? (I need them to be garbage collected)

Était-ce utile?

La solution

If you look at the source code you'll see that this method:

https://github.com/carrotsearch/hppc/blob/master/hppc-core/src/main/templates/com/carrotsearch/hppc/KTypeOpenHashSet.java#L486

  • clears the buffer arrays for primitive types (to the default value)
  • clears object buffers to null (so that objects can be garbage collected)
  • does not release or shrink the buffers themselves (so that arrays are still kept and referenced).

So "Does not release internal buffers." talks about the last bullet (if you have a large collection then it won't release the buffer arrays; may be worth to discard the entire object instead of clearing it).

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top