Skip to content

Commit

Permalink
[impr-OpenMage#61] Fix memory leaks during image upload
Browse files Browse the repository at this point in the history
The image upload - especially during mass imports - leads to memory leaks
 due to consumed memory of the image adapter.

The fix frees the consumed image resources on destruction by calling the
destruct() method on the image adapter.

Note: The root cause is in Varien_Image_Adapter_Gd2, a class that keeps
every created instance in memory until the PHP script exits. This root-
cause remains unfixed with this commit.
  • Loading branch information
ktomk authored and edannenberg committed Aug 22, 2019
1 parent caff027 commit 2562748
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/Varien/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ function __construct($fileName=null, $adapter=Varien_Image_Adapter::ADAPTER_GD2)
}
}

/**
* Destructor
*/
public function __destruct()
{
if (
$this->_adapter instanceof Varien_Image_Adapter_Abstract
&& method_exists($this->_adapter, 'destruct')
) {
$this->_adapter->destruct();
}
}

/**
* Opens an image and creates image handle
*
Expand Down

0 comments on commit 2562748

Please sign in to comment.