Skip to content

The memory of tables created via insertArrowTable is leaked when tables are dropped #2128

@zanettea

Description

@zanettea

What happens?

When creating tables via function insertArrowTable the memory is leaked (not released nor reusable) when the table is dropped.

Memory of tables created directly in duckdb is not released (according to #1904 ) but is reusable after table is dropped

To Reproduce

Consider the following test that inserts new tables and drops them as soon as are created:

                for (let i = 0; i < 100; i++) {
                    conn = await db.connect();

                    const table = arrow.tableFromArrays({
                        a: Int32Array.from({ length: 1000000 }, (_, i) => i),
                        b: Int32Array.from({ length: 1000000 }, (_, i) => i),
                        c: Int32Array.from({ length: 1000000 }, (_, i) => i),
                    });

                    await conn.insertArrowTable(table, { name: `insert_from_vectors_${i}`, create: true });
                    await conn.query(`DROP TABLE IF EXISTS insert_from_vectors_${i}`);

                    await conn.close();
                    await db.flushFiles();
                    await db.dropFiles();
                    await db.flushFiles();
                }

You can check from dev tools that the memory used always increases.

On the other hand, creating the table in duckdb the memory increases just once:

                for (let i = 0; i < 100; i++) {
                    conn = await db.connect();

                    await conn.query(`CREATE TABLE insert_from_vectors_${i} AS SELECT random() AS value FROM range(1, 10000000)`);
                    await conn.query(`DROP TABLE IF EXISTS insert_from_vectors_${i}`);

                    await conn.close();
                    await db.flushFiles();
                    await db.dropFiles();
                    await db.flushFiles();
                }

and according #1904 is never releaesd.

Browser/Environment:

Chrome 141

Device:

PC

DuckDB-Wasm Version:

1.31

DuckDB-Wasm Deployment:

self

Full Name:

Arrigo Zanette

Affiliation:

Corvina srl

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions