-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leak with PDOConnection->prepare() #3047
Comments
@cmorbitzer where is the reference kept, exactly? Any variable that holds it, or is PDO simply broken? |
I think it's a reference inside PDO or PDOStatement. In the examples above, it would appear that the refcount for I'm not well versed enough in the PHP internals to be able to read the PDO source. The comments on the linked bug report suggest that the PHP team is resisting calling this a bug, and rather strongly recommends not extending the PDO class. But composition by itself has its own drawbacks too. |
A bit too late for that now :-) Yeah, this is a PDO bug if the reference is held in internals. It can probably not be GC'd because it's not a normal zval... |
FWIW, as of #2958 |
I'm experiencing this with PHP 7.4 and DBAL 2.10.2 |
@cmorbitzer Did you make any progress on this? |
I misunderstood, thought it was not finished yet, but looks like it is. 👍 I'm using this with Pimcore (see referenced issues above), I'll try to force upgrade the dependencies to the 3.x dev branch and see if it is resolved. |
Hi NiklasBr, did you make any progress here? We have the same problems for bulk importing objects to pimcore and are currently looking for a solution until pimcore upgrades to dbal v3... |
Closing as this seems to be specific for |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Doctrine\DBAL\Driver\PDOConnection()->prepare()
returns a prepared statement with an extra reference to it, so efforts to destroy the statement or close the connection does not free the associated memory in PHP.Scripts that execute many statements (e.g., a script that performs an insert for each chunk of rows returned from a select statement) and daemons that run indefinitely will eventually throw an out of memory error.
For comparison,
PDO()->prepare()
returns a statement that when destroyed does free the associated memory.In fact, it appears that any class that inherits from
PDO
instead of composing a new wrapper class will experience this same issue. This is documented here: https://bugs.php.net/bug.php?id=75190I am using PHP 7.2.2
Examples with comparison:
Using PDO:
Output:
Using a PDOConnection that inherits from PDO:
Output:
Using a composed PDOConnection that wraps PDO:
Output:
The text was updated successfully, but these errors were encountered: