VCL 中的一个内存泄漏 Bug

在valedit.pas中,TValueListStrings类没有实现虚拟的Destroy方法,
它实现了虚拟的Clear方法, 但是它的父类TStringList的
Destroy中并不通过调用Clear()来释放资源,因此TValueListStrings
中为成员ItemProps分配的内存就丢失了.

所以如果在Form中添加了TValueListEditor控件,并且在代码中
使用了其ItemProperty成员(因为它是延迟分配,只有第一次使用时才分配内存),
则需要在Form.Destroy()方法中显式的调用Clear()方法,如下:

MyForm.Destroy()
{
...
MyValueListEditor->Strings->Clear();
...
}

这是在C++ Builder 6的VCL Source中发现的, 估计 Delphi 6中
也应该有这个Bug.

Published At
Categories with Web编程
Tagged with
comments powered by Disqus