[Pkg-owncloud-commits] [php-sabre-vobject] 297/341: Added a garbage collector.

David Prévot taffit at moszumanska.debian.org
Tue Aug 11 13:35:58 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository php-sabre-vobject.

commit 7db3eb63ac9579e74b09126773d75ad9c8f47f88
Author: Evert Pot <me at evertpot.com>
Date:   Sat Jul 4 01:10:30 2015 -0400

    Added a garbage collector.
---
 bin/bench_manipulatevcard.php |  2 ++
 lib/Component.php             | 26 ++++++++++++++++++++++----
 lib/Node.php                  | 15 +++++++++++++++
 lib/Property.php              | 18 ++++++++++++++++++
 4 files changed, 57 insertions(+), 4 deletions(-)

diff --git a/bin/bench_manipulatevcard.php b/bin/bench_manipulatevcard.php
index 454baf3..518eb09 100644
--- a/bin/bench_manipulatevcard.php
+++ b/bin/bench_manipulatevcard.php
@@ -41,6 +41,8 @@ while (true) {
     $vcard2 = $vcard->serialize();
     $bench->serialize->pause();
 
+    $vcard->destroy();
+
 }
 
 
diff --git a/lib/Component.php b/lib/Component.php
index 4408cfd..cdadd41 100644
--- a/lib/Component.php
+++ b/lib/Component.php
@@ -142,9 +142,6 @@ class Component extends Node {
      * pass an instance of a property or component, in which case only that
      * exact item will be removed.
      *
-     * The removed item will be returned. In case there were more than 1 items
-     * removed, only the last one will be returned.
-     *
      * @param mixed $item
      *
      * @return void
@@ -154,14 +151,15 @@ class Component extends Node {
         if (is_string($item)) {
             $children = $this->select($item);
             foreach ($children as $k => $child) {
+                $child->destroy();
                 unset($this->children[$k]);
             }
             return $child;
         } else {
             foreach ($this->children as $k => $child) {
                 if ($child === $item) {
+                    $child->destroy();
                     unset($this->children[$k]);
-                    return $child;
                 }
             }
 
@@ -653,4 +651,24 @@ class Component extends Node {
 
     }
 
+    /**
+     * Call this method on a document if you're done using it.
+     *
+     * It's intended to remove all circular references, so PHP can easily clean
+     * it up.
+     *
+     * @return void
+     */
+    function destroy() {
+
+        parent::destroy();
+        foreach($this->children as $childGroup) {
+            foreach($childGroup as $child) {
+                $child->destroy();
+            }
+        }
+        $this->children = [];
+
+    }
+
 }
diff --git a/lib/Node.php b/lib/Node.php
index 74398a9..3cf833d 100644
--- a/lib/Node.php
+++ b/lib/Node.php
@@ -90,6 +90,21 @@ abstract class Node
      */
     abstract function xmlSerialize(Xml\Writer $writer);
 
+    /**
+     * Call this method on a document if you're done using it.
+     *
+     * It's intended to remove all circular references, so PHP can easily clean
+     * it up.
+     *
+     * @return void
+     */
+    function destroy() {
+
+        $this->parent = null;
+        $this->root = null;
+
+    }
+
     /* {{{ IteratorAggregator interface */
 
     /**
diff --git a/lib/Property.php b/lib/Property.php
index b10b191..09495d4 100644
--- a/lib/Property.php
+++ b/lib/Property.php
@@ -641,4 +641,22 @@ abstract class Property extends Node {
 
     }
 
+    /**
+     * Call this method on a document if you're done using it.
+     *
+     * It's intended to remove all circular references, so PHP can easily clean
+     * it up.
+     *
+     * @return void
+     */
+    function destroy() {
+
+        parent::destroy();
+        foreach($this->parameters as $param) {
+            $param->destroy();
+        }
+        $this->parameters = [];
+
+    }
+
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabre-vobject.git



More information about the Pkg-owncloud-commits mailing list