Ars Nouveau

Ars Nouveau

49M Downloads

Starbuncle memory leak

DBotThePony opened this issue ยท 3 comments

commented

After reading and checking i can't see why this doesn't work the way it should

There is also removeElementAt method:
oJ090Wrc4N


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

public EntityDebugger debugger = new EntityDebugger(this);

3CW5biYuUW

seoVp5xpi1
69UV743wCx

j7o6A7m2Yj

commented

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;
    }
commented

ars_nouveau-1.19.2-3.22.2

commented

This was fixed via ee6638b

But you still should consider using Deque instead of Stack, and in your case LinkedList will do quite well