in reply to Re^2: Why is the base class's destructor not called?
in thread Why is the base class's destructor not called?

In C++, if class Son inherits from class Father, then class Son inherits class Father’s methods and data. So it makes sense that when an object of class Son goes out of scope, the Son destructor is called to clean up the data which Son did not inherit, and then the Father destructor is called to clean up the data Son inherited from Father.

But Perl* is different:

Perl only provides method inheritance as a built-in feature. Attribute inheritance is left up [to] the class to implement.
perlobj

So, from the point of view of the data, there needn’t be any of the Father class in the Son class. So there may be nothing of the Father class to destroy, and no purpose in calling Father’s destructor.

*Meaning the core Perl language, not the various OO frameworks mentioned by tobyink, below.

Hope that helps,

Update (23 Jan 2014): Added [to] to clarify the quote, and reduced the font size of the footnote.

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

  • Comment on Re^3: Why is the base class's destructor not called?