1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-05 06:07:32 +02:00

e107 class destructor - work on Issue #278 Memory leaks

This commit is contained in:
SecretR
2013-05-27 10:54:42 +03:00
parent ae7044cd51
commit c753d7fff6
3 changed files with 48 additions and 0 deletions

View File

@@ -373,6 +373,10 @@ if($tmp1)
$tmp['replace'][] = $tmp1;
}
// Shutdown
$e107->destruct();
if($tmp)
{
$page = str_replace($tmp['search'], $tmp['replace'], ob_get_clean());

View File

@@ -324,6 +324,9 @@ echo "<div style='text-align:center; display:".$show."; position: absolute; widt
unset($show);
echo "\n</body>\n</html>";
// Shutdown
$e107->destruct();
//
// I Send the buffered page data, along with appropriate headers
//

View File

@@ -238,6 +238,9 @@ class e107
*/
protected function __construct()
{
// FIXME registered shutdown functions not executed after the $page output in footer - investigate
// Currently manually called in front-end/admin footer
//register_shutdown_function(array($this, 'destruct'));
}
/**
@@ -3606,4 +3609,42 @@ class e107
$this->{$name} = $ret;
return $ret;
}
public function destruct()
{
if(null === self::$_instance) return;
$print = defined('E107_DBG_TIMEDETAILS') && E107_DBG_TIMEDETAILS;
!$print || print('Destructing $e107: <br />');
$vars = get_object_vars($this);
foreach ($vars as $name => $value)
{
if(is_object($value))
{
if(method_exists($value, '__destruct'))
{
!$print || print('object [property] using __destruct(): '.$path.' - '.get_class($value).'<br />');
$value->__destruct();
}
else !$print || print('object [property]: '.$name.' - '.get_class($value).'<br />');
$this->$name = null;
}
}
foreach (self::$_registry as $path => $reg)
{
if(is_object($reg))
{
if(method_exists($reg, '__destruct'))
{
!$print || print('object [registry] using __destruct(): '.$path.' - '.get_class($reg).'<br />');
$reg->__destruct();
}
else !$print || print('object [registry]: '.$path.' - '.get_class($reg).'<br />');
unset(self::$_registry[$path]);
}
}
self::$_registry = null;
self::$_instance = null;
}
}