Skip to content

Commit 7288b4d

Browse files
authored
WIP Table Destructor (#3707)
There is a circular reference between Worksheet and Table, which can lead to a memory leak. I tried to break this connection in the Worksheet destructor earlier, but this seemed to cause some sort of error with Phpunit 10 on Github, an error that I am unable to duplicate in my local environments. This PR will allow me to explore the problem to see if I can come up with any useful diagnostic data. If I get to a combination that works, I will consider merging it.
1 parent 49a04bd commit 7288b4d

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/PhpSpreadsheet/Worksheet/Table.php

+8
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ public function __construct($range = '', string $name = '')
9292
$this->setName($name);
9393
}
9494

95+
/**
96+
* Code to execute when this table is unset().
97+
*/
98+
public function __destruct()
99+
{
100+
$this->workSheet = null;
101+
}
102+
95103
/**
96104
* Get Table name.
97105
*/

src/PhpSpreadsheet/Worksheet/Worksheet.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ public function __destruct()
444444

445445
$this->disconnectCells();
446446
$this->rowDimensions = [];
447-
//$this->removeTableCollection(); // problem with phpunit10
447+
$this->tableCollection = new ArrayObject();
448448
}
449449

450450
/**

0 commit comments

Comments
 (0)