情况:
窗口1个
定时器线程一个
自定义类(FTP),用于下载文件解析及后续处理住窗口Button --> 定时器线程--->调用FTP的一个方法(DownLoad)在创建定时器线程的时候将FTP的DownLoad方法作为参数传入线程定时器内执行。 FTP的DownLoad中每一个步骤都发送消息到主窗口。如果不间断下载(重复下载),发现任务管理器的内存一直增加。 仔细检查过, DownLoad方法中所有创建的对象都在Fanlly里面销毁了的。初始运行时15M,运行一天后增加到110M
啥原因?
窗口1个
定时器线程一个
自定义类(FTP),用于下载文件解析及后续处理住窗口Button --> 定时器线程--->调用FTP的一个方法(DownLoad)在创建定时器线程的时候将FTP的DownLoad方法作为参数传入线程定时器内执行。 FTP的DownLoad中每一个步骤都发送消息到主窗口。如果不间断下载(重复下载),发现任务管理器的内存一直增加。 仔细检查过, DownLoad方法中所有创建的对象都在Fanlly里面销毁了的。初始运行时15M,运行一天后增加到110M
啥原因?
2894 Error 00000000 0 Attempt to free unexisting resource
22 Error 00000000 0 Attempt to free unexisting resource
25 Error 00000000 0 Attempt to free unexisting resource
1 Error 89050F59 0 Attempt to free unexisting resource
1409 Error 00000000 0 Attempt to free unexisting resource
30 Error 00000000 0 Attempt to free unexisting resource
8 Error 00000000 0 Attempt to free unexisting resource
--------------------------
2894 Error 00000000 0 Attempt to free unexisting resource
22 Error 00000000 0 Attempt to free unexisting resource
00405232 D:\Software\MyProjects\FTPService\Service.exe
0040475E D:\Software\MyProjects\FTPService\Service.exe
7C816FD2 RegisterWaitForInputIdle C:\windows\system32\kernel32.dll
25 Error 00000000 0 Attempt to free unexisting resource
00405232 D:\Software\MyProjects\FTPService\Service.exe
004046F7 D:\Software\MyProjects\FTPService\Service.exe
0040475E D:\Software\MyProjects\FTPService\Service.exe
7C816FD2 RegisterWaitForInputIdle C:\windows\system32\kernel32.dll
1 Error 89050F59 0 Attempt to free unexisting resource
005070C1 D:\Software\MyProjects\FTPService\Service.exe
00509D02 D:\Software\MyProjects\FTPService\Service.exe
004046F7 D:\Software\MyProjects\FTPService\Service.exe
0040475E D:\Software\MyProjects\FTPService\Service.exe
7C816FD2 RegisterWaitForInputIdle C:\windows\system32\kernel32.dll
1409 Error 00000000 0 Attempt to free unexisting resource
004052F1 D:\Software\MyProjects\FTPService\Service.exe
0043B2E2 D:\Software\MyProjects\FTPService\Service.exe
00503353 D:\Software\MyProjects\FTPService\Service.exe
00571CBB D:\Software\MyProjects\FTPService\Service.exe
005723DF D:\Software\MyProjects\FTPService\Service.exe
0044FC7A D:\Software\MyProjects\FTPService\Service.exe
00429E95 D:\Software\MyProjects\FTPService\Service.exe
77D1872F GetDC C:\windows\system32\user32.dll
77D18811 GetDC C:\windows\system32\user32.dll
77D189C8 GetWindowLongW C:\windows\system32\user32.dll
77D196C2 DispatchMessageA C:\windows\system32\user32.dll
0046B8BF D:\Software\MyProjects\FTPService\Service.exe
005738C6 D:\Software\MyProjects\FTPService\Service.exe
7C816FD2 RegisterWaitForInputIdle C:\windows\system32\kernel32.dll
30 Error 00000000 0 Attempt to free unexisting resource
004052F1 D:\Software\MyProjects\FTPService\Service.exe
0043B2E2 D:\Software\MyProjects\FTPService\Service.exe
00503353 D:\Software\MyProjects\FTPService\Service.exe
00571CBB D:\Software\MyProjects\FTPService\Service.exe
005723DF D:\Software\MyProjects\FTPService\Service.exe
0044FC7A D:\Software\MyProjects\FTPService\Service.exe
00429E95 D:\Software\MyProjects\FTPService\Service.exe
77D1872F GetDC C:\windows\system32\user32.dll
77D18811 GetDC C:\windows\system32\user32.dll
77D189C8 GetWindowLongW C:\windows\system32\user32.dll
77D196C2 DispatchMessageA C:\windows\system32\user32.dll
0046B8BF D:\Software\MyProjects\FTPService\Service.exe
0057285B D:\Software\MyProjects\FTPService\Service.exe
0044FFFF D:\Software\MyProjects\FTPService\Service.exe
005724CA D:\Software\MyProjects\FTPService\Service.exe
0044FC7A D:\Software\MyProjects\FTPService\Service.exe
00429E95 D:\Software\MyProjects\FTPService\Service.exe
8 Error 00000000 0 Attempt to free unexisting resource
004052F1 D:\Software\MyProjects\FTPService\Service.exe
0043B2E2 D:\Software\MyProjects\FTPService\Service.exe
00503353 D:\Software\MyProjects\FTPService\Service.exe
00571CBB D:\Software\MyProjects\FTPService\Service.exe
005723DF D:\Software\MyProjects\FTPService\Service.exe
0044FC7A D:\Software\MyProjects\FTPService\Service.exe
00429E95 D:\Software\MyProjects\FTPService\Service.exe
77D1872F GetDC C:\windows\system32\user32.dll
77D18811 GetDC C:\windows\system32\user32.dll
77D1B4BB DefWindowProcW C:\windows\system32\user32.dll
77D1B507 DefWindowProcW C:\windows\system32\user32.dll
7C92EADE KiUserCallbackDispatcher C:\windows\system32\ntdll.dll
77D1D593 DefWindowProcA C:\windows\system32\user32.dll
77D1D540 DefWindowProcA C:\windows\system32\user32.dll
0046AC2A D:\Software\MyProjects\FTPService\Service.exe
0046B332 D:\Software\MyProjects\FTPService\Service.exe然后呢?
to 小云儿,
等会我copy到其他机器上运行看看。
procedure TTimerThread.Execute;
begin
try
inherited;
cb;//run when start
htimerevent := CreateEvent(nil, False, False, nil);
timerid := timesetevent(FInterval,0,TFNTimecallback(htimerevent),0,time_periodic or time_callback_event_set);
repeat
if WaitForSingleObject(htimerevent,INFINITE) = WAIT_OBJECT_0 then
begin
if Terminated then break;
cb;
end;
until false;
timekillevent(timerid);
CloseHandle(htimerevent);
except on e: exception do
Exception.Create(e.Message);
end;
end;CB的定义:TCB = procedure of object;
cb:TCB;在timerThread的构造函数中传入FTP.DownLoad过程
Classes, Windows, mmSystem, TypInfo, Messages;type
TCB = procedure of object; TTimerThread = class(TThread)
private
timerid:integer;
htimerevent:Thandle;
FInterval: integer; cb: TCB;
protected
procedure Execute; override;
public
constructor create(acb: TCB; Interval: Integer; createSuspend: Boolean=True);
destructor destroy; override;
end;implementationuses SysUtils, uFunction;{ TTimerThread }constructor TTimerThread.create(acb: TCB; Interval: Integer; createSuspend: Boolean);
begin
FreeOnTerminate := True;
if Interval<50 then
FInterval := 50
else
FInterval := Interval;
cb:= acb;
inherited create(createSuspend);
end;destructor TTimerThread.destroy;
begin inherited;
end;procedure TTimerThread.Execute;
begin
try
inherited;
cb;//Start run
htimerevent := CreateEvent(nil, False, False, nil);
timerid := timesetevent(FInterval,0,TFNTimecallback(htimerevent),0,time_periodic or time_callback_event_set);
repeat
if WaitForSingleObject(htimerevent,INFINITE) = WAIT_OBJECT_0 then
begin
if Terminated then break;
cb;
end;
until false;
timekillevent(timerid);
CloseHandle(htimerevent);
except on e: exception do
Exception.Create(e.Message);
end;
end;
end.
if Interval <50 then
FInterval := 50
else
FInterval := Interval;
cb:= acb;
inherited create(createSuspend);
这里写的也有问题,在构造函数的时候, inherited 应该是第一行。
可能是Procedure作为参数传入的问题