Memory leak

Author: stubbornbeCreated Jun 22, 2026Updated Jun 22, 2026

System layout OS: Debian 13.5 Webserver: Apache 2.4.67 Php: 8.4 PhpSpreadsheet: 5.8.0

Problem PhpSpreadsheet doesn't release any memory after script end.

Minimalistic script showing issue

$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
$reader->setReadDataOnly(true);
$reader->setLoadSheetsOnly(["MyTab", "MyTab"]);
$worksheet = $reader->load($_FILES['excel']['tmp_name']);

+++Here I should execute some code, but even when I do absolutely nothing here, I already get this behavior+++

$worksheet->disconnectWorksheets();
unset($worksheet);
unset($reader);
\PhpOffice\PhpSpreadsheet\Settings::getCache()->clear();
gc_collect_cycles();

Every time I run this script to read an xlsx file, system memory grows significantly. (No problem with that.) When the above script ends, no memory is released at all. After a couple of runs all system memory is in use and the entire OS locks on heavy swapping. I can't find a way to force a memory release other than an Apache restart. What could be locking? I'm only opening and reading the document.

Source: PHPOffice/PhpSpreadsheet