Skip to content

Possible Memory Leak #472

@Sarjuuk

Description

@Sarjuuk

Version: 5.1.0

Bug Description

Dibi is accumulating memory usage, possibly within the Translator.

Steps To Reproduce

100k iterations each

$points = array_map(fn($x) => (array)$x, DB::Aowow()->fetchAll($query, $mapY, $mapX, $mapY, $mapX, $where));

cumulative RAM usage: 250MB

Within the query, %i, %and, :: were replaced with %d, %s, tblPrefix_ each to make it sprintf-compatible.

$points = [];
$results = DB::Aowow()->getDriver()->query(sprintf($query, $mapY, $mapX, $mapY, $mapX, implode(' AND ', array_map(fn($x) => sprintf(...$x), $where))));
while ($row = $results->fetch(true))
    $points[] = $row;

cumulative RAM usage: 7MB

Expected Behavior

Memory usage should be constant.

Possible Solution

As in reproduction: bypassing the query preparation and using the driver directly sidesteps the problem.
Not a real solution, though.

Notes

Hi,
while migrating my project from the unmaintained DBSimple to Dibi, a setup script that previously ran fine failed because it exhausted 2GB of RAM.
The use case is transforming coordinates for game entities from a global to a local system in SQL, during which the same query loops about 400k-500k times, for different sets of global coordinates.

During reproduction, a break point was set before the first iteration and memory usage at this point was subtracted from the measurement to get the results above.
Script execution was manually interrupted after 100k iterations.

DB::Aowow() is a wrapper returning a \Dibi\Connection.

> php -v
PHP 8.2.12 (cli) (built: Oct 24 2023 21:15:15) (ZTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.2.12, Copyright (c) Zend Technologies
    with Xdebug v3.2.0, Copyright (c) 2002-2022, by Derick Rethans
> SELECT VERSION();
+-----------------+
| VERSION()       |
+-----------------+
| 10.4.32-MariaDB |
+-----------------+
1 row in set (0.000 sec)

Best regards.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions