Paul Posted July 22, 2012 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 Link to comment Share on other sites More sharing options...
Antonio Conte Posted July 22, 2012 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 Link to comment Share on other sites More sharing options...
Paul Posted July 23, 2012 Author Share Posted July 23, 2012 Thanks Antonio. Link to comment Share on other sites More sharing options...
Recommended Posts