File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -22,20 +22,23 @@ final class PostgresConnectionTransaction implements PostgresTransaction
2222
2323 private readonly DeferredFuture $ onClose ;
2424
25+ /** @var array<int, PostgresStatement> Reference statements so de-allocation occurs after commit/rollback. */
26+ private array $ statements = [];
27+
2528 /**
2629 * @param \Closure():void $release
27- *
28- * @throws \Error If the isolation level is invalid.
2930 */
3031 public function __construct (
3132 private readonly PostgresHandle $ handle ,
3233 \Closure $ release ,
3334 private readonly TransactionIsolation $ isolation
3435 ) {
35- $ refCount =& $ this ->refCount ;
36- $ this ->release = static function () use (&$ refCount , $ release ): void {
36+ $ refCount = &$ this ->refCount ;
37+ $ statements = &$ this ->statements ;
38+ $ this ->release = static function () use (&$ refCount , &$ statements , $ release ): void {
3739 if (--$ refCount === 0 ) {
3840 $ release ();
41+ $ statements = [];
3942 }
4043 };
4144
@@ -143,6 +146,8 @@ public function prepare(string $sql): PostgresStatement
143146 throw $ exception ;
144147 }
145148
149+ $ this ->statements [\spl_object_id ($ statement )] ??= $ statement ;
150+
146151 return new PostgresPooledStatement ($ statement , $ this ->release );
147152 }
148153
You can’t perform that action at this time.
0 commit comments