473,386 Members | 2,078 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Nested Object reference

guillermobytes
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:

Expand|Select|Wrap|Line Numbers
  1. class Atom
  2. {
  3.     private $_currentValue;
  4.     private $_origin;
  5.     private $_outdatedAtom;//reference to its old state
  6.  
  7.     public function setValue($value, $origin)
  8.     {
  9.         if (null !== $this->_currentValue) {
  10.             $this->_outdatedAtom = clone $this;
  11.         }
  12.         $this->_origin = $origin;
  13.         $this->_currentValue = $value;
  14.     }
  15.  
  16.     public function unsetOutdatedAtom()
  17.     {
  18.         //help here!
  19.     }
  20. }
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.

Expand|Select|Wrap|Line Numbers
  1. //unset the the $atom outdatedAtom's outdatedAtom reference
  2. $atom->getOutdatedAtom()->unsetOutdatedAtom();
  3. //this would leave us with just one reference, the current atom's outdatedAtom, all references down the chain are lost
What i need to know for the implementation of unsetOutdatedAtom() (aka cutOutdatedAtomChain) is: do i need to go all down the chain of references and call the unsetOutdatedAtom() 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.
Apr 13 '10 #1
10 2440
@guillermobytes
Ok i will abstract my question:

whenever an object is the only one referencing a set of other objects.
if that object gets unset, will the objects that it references get cleaned from memory?
Apr 13 '10 #2
Dormilich
8,658 Expert Mod 8TB
out of curiousity, why do you need nested objects?
Apr 13 '10 #3
@Dormilich
well maybe I didn't express it well, by nested object reference i mean that an object has a property which is a pointer to another object, which in turn has a property that is a pointer to another etc.

I need that because every parent has a child and every child is a parent

I don't know how to explain it better.

btw do you know if i kill the parent object, will its childs get removed from memory?
Apr 13 '10 #4
Dormilich
8,658 Expert Mod 8TB
@guillermobytes
I did understand that part, but not why you would need that.


@guillermobytes
I guess, but I’m not familiar with PHP’s memory internals
Apr 13 '10 #5
@Dormilich
because I can't figure out a way to represent that parent->child relationship other than with nested reference. I can use an array but as I like to program OO I need nested reference.
Apr 13 '10 #6
Dormilich
8,658 Expert Mod 8TB
I’m sure there is a better solution for your problem. the nested objects just don’t feel right.
Apr 14 '10 #7
This works fine, nested reference is used everywhere in OOP. But if you see another approach i would be glad to have a look at it
Apr 14 '10 #8
Dormilich
8,658 Expert Mod 8TB
yea, one or two levels … that’s still manageable. and most often those child classes are of a different class.

I would have to know what you want to do, to give you a sensible answer.
Apr 14 '10 #9
Markus
6,050 Expert 4TB
Memory is only released once there are no references to a variable/object/resource left.
Apr 14 '10 #10
ok thanks Markus
Apr 14 '10 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Pkpatel | last post by:
Hi, I keep getting this error every time I try to load crystalreportviewer on a webform with a dataset. Here is the error: -------------------------------------------------------- Server...
10
by: Philip Ronan | last post by:
Hi, I'm having problems embedding alternative content with nested OBJECT tags. Take a look at <http://www.japanesetranslator.co.uk/chihiro/map.html> The map on this page is available in SVG,...
1
by: Robert A Riedel | last post by:
I am completely baffled when the following managed exception is thrown: "Object reference not set to an instance of an object" from a nested subroutine when referencing a variable allocated on the...
1
by: Martine | last post by:
Hi there! I have a problem with programmatically adding user controls to my mobile webforms. If I load my usercontrol programmatically (in the Page_Load), the object is instantiated, I have...
0
by: SK | last post by:
Hello, I have a datagrid, which contains another nested datagrid as a user control. The nested dg is popultated when the user presses the "+" button in one row for the main grid. I have a...
2
by: jw56578 | last post by:
why am i getting the "Object reference not set to an instance of an object" error on all page registeration tags in my project. <%@ Page Language="vb" AutoEventWireup="false"...
3
by: Adam | last post by:
We have a web site that uses .vb for the web pages and .cs for a class module. We are getting the error in .NET 2.0 and VS 2005 beta 2. It does work with .NET 1.1. When trying to access a page...
3
by: mbaskey | last post by:
Hello... I have an object which has a nested object which need to look at the parent to return a value about it. Basically as below but when I put the ref method parameter to construct the...
6
mshmyob
by: mshmyob | last post by:
I am using VS2008 and vb.net I have a nested tabcontrol. tabControl 1 and tabControl3 In tabControl3 I am trying to populate a text control with a value from a control placed on tabControl1....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.