Destructing an object/Constructing
Posted: Mon Jul 27, 2009 11:44 pm
Hi,
I have a class (call it main) defined, and in it are variables that point to instances of other classes.
If I have an instance of this main class (which in turn has instances of other classes its vars point to), and I __destruct the instance of the main class; what happens to the other objects that main's variables pointed to? do they get destructed as well, or are they garbage collected and do they still take up memory on the server until the script is finished executing?
Also, say Im writing something that creates many instances of main (in a for loop, a new instance each iteration). Would it be better to destruct the object at the end of every iteration? does it even make a difference? If I dont destruct it, does it just get garbage collected; and is garbage collection the same as destructing?
And thirdly about constructors: are constructors automatically called when a new object is created? does it work in the same way that Java uses constructors, where you can have more than one (as long as their input vars are different)?
Thanks
I have a class (call it main) defined, and in it are variables that point to instances of other classes.
If I have an instance of this main class (which in turn has instances of other classes its vars point to), and I __destruct the instance of the main class; what happens to the other objects that main's variables pointed to? do they get destructed as well, or are they garbage collected and do they still take up memory on the server until the script is finished executing?
Also, say Im writing something that creates many instances of main (in a for loop, a new instance each iteration). Would it be better to destruct the object at the end of every iteration? does it even make a difference? If I dont destruct it, does it just get garbage collected; and is garbage collection the same as destructing?
And thirdly about constructors: are constructors automatically called when a new object is created? does it work in the same way that Java uses constructors, where you can have more than one (as long as their input vars are different)?
Thanks