Previous: 2.2.13.10. Using New Procedure (OOP) To the Table of Contents Next: 2.2.13.12. Inherited reserved word
2.2.13.10. Using New Procedure (OOP) Table of Contents 2.2.13.12. Inherited reserved word

- 2.2.13.11. -
Table of Contents
2. TMT Pascal Language Description
2.2. Pascal Language Structure
2.2.13. OOP Extensions
2.2.13.11. Desctructors


2.2.13.11. Destructors


Destructors are used to clean up after an object is no longer needed. Unlike constructors, destructors can be virtual. Destruction of an object is often combined with deallocation of its memory with the Dispose procedure:
var
  C: ^Circle;
begin
  New(C);
  C.Init(P,R);
  ...
  C.Kill;
  Dispose(C);
end;
If a constructor fails to perform initialization (often because of its inability to allocate memory for the structures affiliated with the object, it can execute a special system function Fail. Fail signals TMT Pascal to reverse all allocation of the object that might have occurred and return nil as the value of the object's pointer. Fail can be called only within constructors.

See also:
Constructors


Previous: 2.2.13.10. Using New Procedure (OOP) To the Table of Contents Next: 2.2.13.12. Inherited reserved word
2.2.13.10. Using New Procedure (OOP) Table of Contents 2.2.13.12. Inherited reserved word

- 2.2.13.11. -