PHPExcel内存泄漏问题解决方法 |
本文标签:PHPExcel,内存泄漏 使用 PHPExcel 来生成 excel 文档是比较消耗内存的,有时候可能会需要通过一个循环来把大数据切分成若干个小的 excel 文档保存来避免内存耗尽 。 复制代码 代码如下: public function Destroy() { foreach($this->_cellCollection as $index => $dummy) { $this->_cellCollection[$index] = null; } } 并在 PHPExcel 类中增加方法: 复制代码 代码如下: public function Destroy() { foreach($this->_workSheetCollection as $index => $dummy) { $this->_workSheetCollection[$index]->Destroy(); $this->_workSheetCollection[$index] = null; } } 然后在需要资源回收的地方显式的调用 PHPExcel::Destroy() 来处理循环引用的问题 。注意 __destruct() 方法是在对象被认为可以被释放的时候才会被调用,所以循环引用的处理不能放到 __destruct() 来进行 。 |