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:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user