You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a person were to make a large circular buffer, and fill it up and subsequently empty it, all the objects placed into it have a strong reference, and thus can't be garbage collected, until they're overwritten by new objects which will then have the same problem. To fix this, your get() method should assign the element in the array to null when the object is returned.
The text was updated successfully, but these errors were encountered:
@PH0lder I have had a look at this but I am not sure I can do that without breaking the existing behaviour of get on an Unordered Ring Buffer.
For example, if I had the suggested entries[readIdx] = null; at line 169 of RingBuffer.java, then the test in RingBufferTest.java: putGetPutGetUnordered(7, 10, 2, 2, 16) shows the following behaviour:
capacity(7):
0, 1, 2, 3, 4, 5, 6
[N, N, N, N, N, N, N]
put1(10):
[a, b, c, d, e, f, g]
[h, i, j ]
=>
[h, i, j, d, e, f, g]
get1(2):
[N, N, j, d, e, f, g]
put2(2):
[N, N, j, d, e, f, g]
[ a, b ]
=>
[N, N, j, a, b, f, g]
get2(16):
[N, N, j, a, b, f, g]
The second get operation (get2) is now returning the wrong results, it should have returned: [a, b, f, g, h, i, j]
If a person were to make a large circular buffer, and fill it up and subsequently empty it, all the objects placed into it have a strong reference, and thus can't be garbage collected, until they're overwritten by new objects which will then have the same problem. To fix this, your
get()
method should assign the element in the array to null when the object is returned.The text was updated successfully, but these errors were encountered: