Paul 6 Posted July 22, 2012 Report Share Posted July 22, 2012 Hi all, hope you're all well. A general question regarding constructors and destructors. I can see (I think) why constructors are useful: in that they are automatically and immediantly called when an object is created, so you know that it'll always be done. However I'm confused about what destructors are for. If unset removes objects and it all gets removed when the script finishes anyway what do destructors do? I've worked through Larry's example (script 6.7) so I can see the how and when but I'm missing the why! Cheers Paul Quote Link to post Share on other sites
Antonio Conte 426 Posted July 22, 2012 Report Share Posted July 22, 2012 Destructors allow you determine any last actions that should be performed by an object. Maybe you'll save it in a database, notify another object that is gone, or something similar. The garbage collector is generally good at removing unused objects from memory, so it's often these extra, last minute things you want to do. I have never programmed a destructor myself. They are not needed most of the time. 1 Quote Link to post Share on other sites
Paul 6 Posted July 23, 2012 Author Report Share Posted July 23, 2012 Thanks Antonio. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.