From c753d7fff613e113081ae775ead8f98e7e59705d Mon Sep 17 00:00:00 2001 From: SecretR Date: Mon, 27 May 2013 10:54:42 +0300 Subject: [PATCH] e107 class destructor - work on Issue #278 Memory leaks --- e107_admin/footer.php | 4 +++ e107_core/templates/footer_default.php | 3 ++ e107_handlers/e107_class.php | 41 ++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/e107_admin/footer.php b/e107_admin/footer.php index 87aeb17a3..b193a4666 100644 --- a/e107_admin/footer.php +++ b/e107_admin/footer.php @@ -373,6 +373,10 @@ if($tmp1) $tmp['replace'][] = $tmp1; } + +// Shutdown +$e107->destruct(); + if($tmp) { $page = str_replace($tmp['search'], $tmp['replace'], ob_get_clean()); diff --git a/e107_core/templates/footer_default.php b/e107_core/templates/footer_default.php index b055f4093..c9994189e 100644 --- a/e107_core/templates/footer_default.php +++ b/e107_core/templates/footer_default.php @@ -324,6 +324,9 @@ echo "
{$name} = $ret; return $ret; } + + public function destruct() + { + if(null === self::$_instance) return; + + $print = defined('E107_DBG_TIMEDETAILS') && E107_DBG_TIMEDETAILS; + !$print || print('Destructing $e107:
'); + $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).'
'); + $value->__destruct(); + } + else !$print || print('object [property]: '.$name.' - '.get_class($value).'
'); + $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).'
'); + $reg->__destruct(); + } + else !$print || print('object [registry]: '.$path.' - '.get_class($reg).'
'); + unset(self::$_registry[$path]); + } + + } + self::$_registry = null; + self::$_instance = null; + } }