Starbuncle memory leak
DBotThePony opened this issue ยท 3 comments
After reading and checking i can't see why this doesn't work the way it should
There is also removeElementAt
method:
Any reason why you don't use Deque<>
implementations (example: ArrayDeque<>
or LinkedList<>
), and instead use Stack<>
? LinkedList<>
works really good when list is relatively small and you do a lot of push/pop on both sides of deque
Hello, thank you for looking into this.
What version are you testing on? I tested by adding 1,000 elements to the debugger and only see 100 logged to the file.
@Override
public InteractionResult useOn(UseOnContext context) {
if (!context.getLevel().isClientSide) {
try {
// Write the file
Path path = Paths.get("ars_nouveau", "entity_log_" + System.currentTimeMillis() + ".log");
File file = path.toFile();
Files.createDirectories(path.getParent());
PrintWriter w = new PrintWriter(new FileWriterWithEncoding(file, "UTF-8", false));
EntityDebugger debugger = new EntityDebugger(new Starbuncle(context.getLevel(), true));
for (int i = 0; i < 1000; i++) {
debugger.addEntityEvent(new DebugEvent("test" + i, "test" + i));
}
debugger.writeFile(w);
System.out.println(debugger.events.size());
w.close();
} catch (Exception e) {
e.printStackTrace();
}
}
return super.useOn(context);
}
The file maintains the 900th to 999.
The implementation for remove and removeAt are nearly identical.
/**
* Removes the element at the specified position in this Vector.
* Shifts any subsequent elements to the left (subtracts one from their
* indices). Returns the element that was removed from the Vector.
*
* @param index the index of the element to be removed
* @return element that was removed
* @throws ArrayIndexOutOfBoundsException if the index is out of range
* ({@code index < 0 || index >= size()})
* @since 1.2
*/
public synchronized E remove(int index) {
modCount++;
if (index >= elementCount)
throw new ArrayIndexOutOfBoundsException(index);
E oldValue = elementData(index);
int numMoved = elementCount - index - 1;
if (numMoved > 0)
System.arraycopy(elementData, index+1, elementData, index,
numMoved);
elementData[--elementCount] = null; // Let gc do its work
return oldValue;
}
This was fixed via ee6638b
But you still should consider using Deque instead of Stack, and in your case LinkedList will do quite well