Does every Class we create in Delphi need to have destructor?
When I create my custom Class in Delphi Application I use standard procedure:
TCustomClass = Class
private
var1,var2 : integer/string/Real/Boolean...
procedure P1...
function F1...
public
constructor Create;
end;
...
CustomClass := TCustomClass.create;
I want to know do I always have to also create Destructor procedure or are resources automatically free when application closes?
I always use Application as owner, rarely Self or Nil and I don't remember I saw anyone declaring Destructor on classes I saw on Internet, except for one when someone used pointers.
Is the logic behind destructor same in Delphi as in C++ as described in this question:
Should every class have a virtual destructor?
Thanks in advance.
EDIT1: As Free Consulting mentioned I forgot to say that one of the variables might be TBitmap type
It only needs to have a destructor if you need to clean up something, like allocated memory. For example, if you have used TClassname.Create(...) in the constructor, you need to free in the destructor method.
Of course there can be many different reasons to need a destructor (all the way up to informing the user that his data is about to get wiped), but this is the most common one.
链接地址: http://www.djcxy.com/p/34946.html上一篇: 通过PHP中的SFTP传输大文件