src/Mouf/MoufManager.php
public function walkForGarbageCollection($instanceName) {
        // In case the instance does not exist (this could happen after a failed merge or a manual edit of MoufComponents.php...)
        if (!isset($this->declaredInstances[$instanceName])) {
            return;
        }
		$instance = &$this->declaredInstances[$instanceName];
		if (isset($instance['noGarbageCollect']) && $instance['noGarbageCollect'] == true) {
			// No need to go through already visited nodes.
			return;
		}

		$instance['noGarbageCollect'] = true;

		$declaredInstances = &$this->declaredInstances;
		$moufManager = $this;
		if (isset($instance['constructor'])) {
			foreach ($instance['constructor'] as $argument) {
				if ($argument["parametertype"] == "object") {
					$value = $argument["value"];
					if(is_array($value)) {
						array_walk_recursive($value, function($singleValue) use (&$declaredInstances, $moufManager) {
							if ($singleValue != null) {
								$moufManager->walkForGarbageCollection($singleValue);
							}
						});
						/*foreach ($value as $singleValue) {
							if ($singleValue != null) {
								$this->walkForGarbageCollection($this->declaredInstances[$singleValue]);
							}
						}*/
					}
					else {
						if ($value != null) {
							$this->walkForGarbageCollection($value);
						}
					}
				}

			}
		}
		if (isset($instance['fieldBinds'])) {
			foreach ($instance['fieldBinds'] as $prop) {
				if(is_array($prop)) {
					array_walk_recursive($prop, function($singleProp) use (&$declaredInstances, $moufManager) {
						if ($singleProp != null) {
							$moufManager->walkForGarbageCollection($singleProp);
						}
					});
							
					/*foreach ($prop as $singleProp) {
						if ($singleProp != null) {
							$this->walkForGarbageCollection($this->declaredInstances[$singleProp]);
						}
					}*/
				}
				else {
					$this->walkForGarbageCollection($prop);
				}
			}
		}
		if (isset($instance['setterBinds'])) {
			foreach ($instance['setterBinds'] as $prop) {
				if(is_array($prop)) {
					array_walk_recursive($prop, function($singleProp) use (&$declaredInstances, $moufManager) {
						if ($singleProp != null) {
							$moufManager->walkForGarbageCollection($singleProp);
						}
					});
					/*foreach ($prop as $singleProp) {
						if ($singleProp != null) {
							$this->walkForGarbageCollection($this->declaredInstances[$singleProp]);
						}
					}*/
					
				}
				else {
					$this->walkForGarbageCollection($prop);
				}
			}
		}
	}
public function walkForGarbageCollection($instanceName) {
        // In case the instance does not exist (this could happen after a failed merge or a manual edit of MoufComponents.php...)
        if (!isset($this->declaredInstances[$instanceName])) {
            return;
        }
		$instance = &$this->declaredInstances[$instanceName];
		if (isset($instance['noGarbageCollect']) && $instance['noGarbageCollect'] == true) {
			// No need to go through already visited nodes.
			return;
		}

		$instance['noGarbageCollect'] = true;

		$declaredInstances = &$this->declaredInstances;
		$moufManager = $this;
		if (isset($instance['constructor'])) {
			foreach ($instance['constructor'] as $argument) {
				if ($argument["parametertype"] == "object") {
					$value = $argument["value"];
					if(is_array($value)) {
						array_walk_recursive($value, function($singleValue) use (&$declaredInstances, $moufManager) {
							if ($singleValue != null) {
								$moufManager->walkForGarbageCollection($singleValue);
							}
						});
						/*foreach ($value as $singleValue) {
							if ($singleValue != null) {
								$this->walkForGarbageCollection($this->declaredInstances[$singleValue]);
							}
						}*/
					}
					else {
						if ($value != null) {
							$this->walkForGarbageCollection($value);
						}
					}
				}

			}
		}
		if (isset($instance['fieldBinds'])) {
			foreach ($instance['fieldBinds'] as $prop) {
				if(is_array($prop)) {
					array_walk_recursive($prop, function($singleProp) use (&$declaredInstances, $moufManager) {
						if ($singleProp != null) {
							$moufManager->walkForGarbageCollection($singleProp);
						}
					});
							
					/*foreach ($prop as $singleProp) {
						if ($singleProp != null) {
							$this->walkForGarbageCollection($this->declaredInstances[$singleProp]);
						}
					}*/
				}
				else {
					$this->walkForGarbageCollection($prop);
				}
			}
		}
		if (isset($instance['setterBinds'])) {
			foreach ($instance['setterBinds'] as $prop) {
				if(is_array($prop)) {
					array_walk_recursive($prop, function($singleProp) use (&$declaredInstances, $moufManager) {
						if ($singleProp != null) {
							$moufManager->walkForGarbageCollection($singleProp);
						}
					});
					/*foreach ($prop as $singleProp) {
						if ($singleProp != null) {
							$this->walkForGarbageCollection($this->declaredInstances[$singleProp]);
						}
					}*/
					
				}
				else {
					$this->walkForGarbageCollection($prop);
				}
			}
		}
	}
public function walkForGarbageCollection ( $ instanceName ) { // In case the instance does not exist (this could happen after a failed merge or a manual edit of MoufComponents.php...)
 if ( ! isset ( $ this -> declaredInstances [ $ instanceName ] ) ) { return ; } $ instance = & $ this -> declaredInstances [ $ instanceName ] ; if ( isset ( $ instance [ 'noGarbageCollect' ] ) && $ instance [ 'noGarbageCollect' ] == true ) { // No need to go through already visited nodes.
 return ; } $ instance [ 'noGarbageCollect' ] = true ; $ declaredInstances = & $ this -> declaredInstances ; $ moufManager = $ this ; if ( isset ( $ instance [ 'constructor' ] ) ) { foreach ( $ instance [ 'constructor' ] as $ argument ) { if ( $ argument [ "parametertype" ] == "object" ) { $ value = $ argument [ "value" ] ; if ( is_array ( $ value ) ) { array_walk_recursive ( $ value , function ( $ singleValue ) use ( & $ declaredInstances , $ moufManager ) { if ( $ singleValue != null ) { $ moufManager -> walkForGarbageCollection ( $ singleValue ) ; } } ) ; /*foreach ($value as $singleValue) {
							if ($singleValue != null) {
								$this->walkForGarbageCollection($this->declaredInstances[$singleValue]);
							}
						}*/ } else { if ( $ value != null ) { $ this -> walkForGarbageCollection ( $ value ) ; } } } } } if ( isset ( $ instance [ 'fieldBinds' ] ) ) { foreach ( $ instance [ 'fieldBinds' ] as $ prop ) { if ( is_array ( $ prop ) ) { array_walk_recursive ( $ prop , function ( $ singleProp ) use ( & $ declaredInstances , $ moufManager ) { if ( $ singleProp != null ) { $ moufManager -> walkForGarbageCollection ( $ singleProp ) ; } } ) ; /*foreach ($prop as $singleProp) {
						if ($singleProp != null) {
							$this->walkForGarbageCollection($this->declaredInstances[$singleProp]);
						}
					}*/ } else { $ this -> walkForGarbageCollection ( $ prop ) ; } } } if ( isset ( $ instance [ 'setterBinds' ] ) ) { foreach ( $ instance [ 'setterBinds' ] as $ prop ) { if ( is_array ( $ prop ) ) { array_walk_recursive ( $ prop , function ( $ singleProp ) use ( & $ declaredInstances , $ moufManager ) { if ( $ singleProp != null ) { $ moufManager -> walkForGarbageCollection ( $ singleProp ) ; } } ) ; /*foreach ($prop as $singleProp) {
						if ($singleProp != null) {
							$this->walkForGarbageCollection($this->declaredInstances[$singleProp]);
						}
					}*/ } else { $ this -> walkForGarbageCollection ( $ prop ) ; } } } }
Recursive function that mark this instance as NOT garbage collectable and go through referred nodes.

@param string $instanceName
Recursive function that mark this instance as NOT garbage collectable and go through referred nodes .