Skip to content

Commit

Permalink
WIP Table Destructor (#3707)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
oleibman authored Sep 3, 2023
1 parent 49a04bd commit 7288b4d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/PhpSpreadsheet/Worksheet/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ public function __construct($range = '', string $name = '')
$this->setName($name);
}

/**
* Code to execute when this table is unset().
*/
public function __destruct()
{
$this->workSheet = null;
}

/**
* Get Table name.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Worksheet/Worksheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ public function __destruct()

$this->disconnectCells();
$this->rowDimensions = [];
//$this->removeTableCollection(); // problem with phpunit10
$this->tableCollection = new ArrayObject();
}

/**
Expand Down

0 comments on commit 7288b4d

Please sign in to comment.