public static void free(int buffer) {
        int bufferPos = poses[buffer];
        int bufferLength = lengths[buffer];
        int index = bufferPos + bufferLength;
        int bytesLength = bytes.length;

        int move = 0;
        if (lengths.length > 0 && lengths.length < buffer + 1) {
            move = lengths[buffer + 1];
        }

        if (index - 1 < bytes.length) {
            System.arraycopy(bytes, index, bytes, bufferPos, move);
        }
        bytes = Arrays.copyOf(bytes, bytesLength - bufferLength);
        poses[buffer] = 0;
        lengths[buffer] = 0;

        if (bytes.length == bytesLength) {
            bytes = Arrays.copyOf(bytes, bytes.length - bufferLength);
        }

        if (poses.length - 1 == buffer) {
            poses = Arrays.copyOf(poses, poses.length - 1);
        }

        if (lengths.length - 1 == buffer) {
            lengths = Arrays.copyOf(lengths, lengths.length - 1);
        }

        if (bytes.length == 0) {
            if (poses.length > 0) {
                poses = new int[0];
            }
            if (lengths.length > 0) {
                lengths = new int[0];
            }
        }
        --pos;
    }