clear() not longer frees memory it just empties the list

Use case: The list is used as a buffer, that is re-used and in
each iteration the list is cleared.

Now that clear() does not replace the data array there is no
garbage collection and we do not have to allocated one or
several new arrays in the next iteration.
You can still free the associated memory by calling clear() + trim().
This commit is contained in:
2018-08-17 19:38:30 +02:00
parent 1994400f97
commit 336905fafe
4 changed files with 22 additions and 22 deletions

View File

@@ -589,13 +589,12 @@ public final class IntList implements Serializable, Cloneable {
}
/**
* Removes all elements from this list.
* Removes all elements from the list.
* <p>
* The implementation is equivalent to calling {@code remove(0, size())} and
* {@code trim()}.
* This method does not free any memory associated with this list. Call
* {@link #clear()} + {@link #trim()} to free associated memory.
*/
public void clear() {
data = EMPTY_ARRAY;
size = 0;
sorted = true;
}

View File

@@ -575,13 +575,12 @@ public final class LongList implements Serializable, Cloneable {
}
/**
* Removes all elements from this list.
* Removes all elements from the list.
* <p>
* The implementation is equivalent to calling {@code remove(0, size())} and
* {@code trim()}.
* This method does not free any memory associated with this list. Call
* {@link #clear()} + {@link #trim()} to free associated memory.
*/
public void clear() {
data = EMPTY_ARRAY;
size = 0;
sorted = true;
}