Hi,
I'm creating a class, that clones itself whenever it gets a new value.
Each instance has a set of properties that are related to the value it gets:
whenever i pass a new value to setValue(), the instance gets cloned and i keep a reference of the old instance state.
So if y pass a new value to setValue() 10 times, i get a nested reference of 9 objects,
I want to create a method that would allow to cut the reference chain from the instance it is called in.
What i need to know for the implementation of unsetOutdatedAt om() (aka cutOutdatedAtom Chain) is: do i need to go all down the chain of references and call the unsetOutdatedAt om() method from the last atom that has an outdatedAtom reference, or just unsetting the current outdatedAtom's reference will be enough.
I ask this because i dont want to have a big chain of outdated atoms that get dereferenced and occupy memory space.
I dont know if i made myself clear.
I'm creating a class, that clones itself whenever it gets a new value.
Each instance has a set of properties that are related to the value it gets:
Code:
class Atom
{
private $_currentValue;
private $_origin;
private $_outdatedAtom;//reference to its old state
public function setValue($value, $origin)
{
if (null !== $this->_currentValue) {
$this->_outdatedAtom = clone $this;
}
$this->_origin = $origin;
$this->_currentValue = $value;
}
public function unsetOutdatedAtom()
{
//help here!
}
}
So if y pass a new value to setValue() 10 times, i get a nested reference of 9 objects,
I want to create a method that would allow to cut the reference chain from the instance it is called in.
Code:
//unset the the $atom outdatedAtom's outdatedAtom reference $atom->getOutdatedAtom()->unsetOutdatedAtom(); //this would leave us with just one reference, the current atom's outdatedAtom, all references down the chain are lost
I ask this because i dont want to have a big chain of outdated atoms that get dereferenced and occupy memory space.
I dont know if i made myself clear.
Comment