一个线程问题,请大家看看我的程序错在哪儿?为什么占用的内存不会失放掉啊!!,运行不久就死机啊!!!
 unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, ADODB, ExtCtrls;type
  TForm1 = class(TForm)
    ADOConnection1: TADOConnection;
    Timer1: TTimer;
    ADOQuery1: TADOQuery;
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 TVoice=class(TThread)                            //进行保存
 protected
     procedure Execute; override;
  end;var
  Form1: TForm1;implementation{$R *.dfm}
procedure TVoice.Execute;
begin
      with form1.ADOQuery1 do
      try
         if Active  then  close;
         SQL.Text:='select * from msghis';
         Open;
         if RecordCount>0 then
         Begin
         end;
       finally
         close;
       end;end;procedure TForm1.Timer1Timer(Sender: TObject);
begin
     with form1.ADOQuery1 do
      try
         if Active  then  close;
         SQL.Text:='select * from msghis';
         Open;
         if RecordCount>0 then
         Begin
         end;
       finally
         close;
       end;
    TVoice.create(false);
end;end.

解决方案 »

  1.   

    procedure TVoice.Execute;
    begin
         FreeOnTerminate := True;//加上这句话
          with form1.ADOQuery1 do
          try
             if Active  then  close;
             SQL.Text:='select * from msghis';
             Open;
             if RecordCount>0 then
             Begin
             end;
           finally
             close;
           end;end;
      

  2.   

    madyak(无天),您好,我加了也没有用,内存也是不会啊
      

  3.   

    线程不应该像这样玩,在单CPU的PC机器上,16以上的线程就是线程非安全的,好像是16个,不记得。
        线程如果没有必要用,就不要用,如果要用,就最好保证:一次创建,长时间运用,然后一次销毁。madyak的的做法是能把资源销毁的,出错是可能其它的原因啊,用法有问题,建议你先调整一下用法。