It's hard to understand what you are actually asking here, but the application behaves exactly as I expected.
The rows are immutable and the garbage collector does not take them out. It's not him
Both mutable and immutable objects can be garbage collected in Java.
The actual criterion for determining whether an object is actually collecting garbage is reachability. Simply put, when the garbage collector finds out that the application can no longer use the object, the object will be deleted.
In both of your applications, objects of approximately the same size are created once every 10 milliseconds. At each iteration, a new object is created, and its link is assigned to s , replacing the previous link. This makes the previous object inaccessible and has the right to garbage collection. At some point, the Java virtual machine decides to run the garbage collector. This eliminates the whole unreachable object ... and the application continues.
I read that regular strings are not collected by the garbage collector, is that a lie?
This is not true for two counters:
The strings created by new String(...) , String.substring(...) , etc., are no different from any other Java object.
Lines that are interned (by calling String.intern() ) are stored in the row pool, which is stored in the PermGen heap. However, even the PermGen heap is garbage collection, albeit on a longer time scale, that the heap in which objects are usually created.
(Once upon a time, a PermGen heap was not garbage collected, but it was changed a long time ago.)
source share