PhpSpreadsheet/docs/Overview/05-Deleting-a-Workbook.md

14 lines
773 B
Markdown
Raw Normal View History

2016-11-27 15:51:44 +00:00
# PhpSpreadsheet Developer Documentation
2013-05-16 23:09:14 +00:00
## Clearing a Workbook from memory
2016-11-27 15:51:44 +00:00
The PhpSpreadsheet object contains cyclic references (e.g. the workbook is linked to the worksheets, and the worksheets are linked to their parent workbook) which cause problems when PHP tries to clear the objects from memory when they are unset(), or at the end of a function when they are in local scope. The result of this is "memory leaks", which can easily use a large amount of PHP's limited memory.
2013-05-16 23:09:14 +00:00
2016-11-27 15:51:44 +00:00
This can only be resolved manually: if you need to unset a workbook, then you also need to "break" these cyclic references before doing so. PhpSpreadsheet provides the disconnectWorksheets() method for this purpose.
2013-05-16 23:09:14 +00:00
```php
2016-11-27 15:51:44 +00:00
$spreadsheet->disconnectWorksheets();
2013-05-16 23:09:14 +00:00
2016-11-27 15:51:44 +00:00
unset($spreadsheet);
2013-05-16 23:09:14 +00:00
```