MDL-24962 backup - now destroying circular refs manually to help PHP 5.2
authorEloy Lafuente <stronk7@moodle.org>
Mon, 1 Nov 2010 22:09:44 +0000 (22:09 +0000)
committerEloy Lafuente <stronk7@moodle.org>
Mon, 1 Nov 2010 22:09:44 +0000 (22:09 +0000)
backup/util/plan/backup_structure_step.class.php
backup/util/structure/base_final_element.class.php
backup/util/structure/base_nested_element.class.php

index 970e775..29b76ac 100644 (file)
@@ -96,6 +96,9 @@ abstract class backup_structure_step extends backup_step {
 
         // Close everything
         $xw->stop();
+
+        // Destroy the structure. It helps PHP 5.2 memory a lot!
+        $structure->destroy();
     }
 
 // Protected API starts here
index 35f4fbf..0bac3a0 100644 (file)
@@ -50,6 +50,15 @@ abstract class base_final_element extends base_atom {
         $this->parent = null;
     }
 
+    /**
+     * Destroy all circular references. It helps PHP 5.2 a lot!
+     */
+    public function destroy() {
+        // No need to destroy anything recursively here, direct reset
+        $this->attributes = array();
+        $this->parent = null;
+    }
+
     protected function set_parent($element) {
         if ($this->parent) {
             $info = new stdClass();
index f2dc77f..1cd23b0 100644 (file)
@@ -59,6 +59,28 @@ abstract class base_nested_element extends base_final_element {
         $this->used[] = $name;
     }
 
+    /**
+     * Destroy all circular references. It helps PHP 5.2 a lot!
+     */
+    public function destroy() {
+        // Before reseting anything, call destroy recursively
+        foreach ($this->children as $child) {
+            $child->destroy();
+        }
+        foreach ($this->final_elements as $element) {
+            $element->destroy();
+        }
+        if ($this->optigroup) {
+            $this->optigroup->destroy();
+        }
+        // Everything has been destroyed recursively, now we can reset safely
+        $this->children = array();
+        $this->final_elements = array();
+        $this->optigroup = null;
+        // Delegate to parent to destroy other bits
+        parent::destroy();
+    }
+
     protected function get_used() {
         return $this->used;
     }