动态调用dll占用内存越来越多的问题。
tomp 2007-11-15 03:26:55 dll的代码:
=====================
library Project2;
uses
SysUtils,
Classes,
Unit1 in 'Unit1.pas';
exports testdll,addtest;
begin
end.
--------------
unit Unit1;
interface
procedure testdll;stdcall;//export;
implementation
procedure testdll;
begin
end;
end.
=====================
动态调用dll的代码
================================
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
test=procedure();stdcall;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
testpro:test; { Public declarations }
end;
var
Form1: TForm1;
testhandle:thandle; //句柄
testpointer:pointer; //定义过程入口指针
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
testhandle:=loadlibrary('c:\project2.dll'); //装载project2.DLL文件
if testhandle>0 then
try
testpointer:=getprocaddress(testhandle,pchar('testdll'));//获取project2.DLL的testdll过程
if testpointer<>nil then begin
testpro:=test(testpointer); //把project2.DLL的testdll过程传给project.ext的testpro过程
testpro;
end;
finally
freelibrary(testhandle); //释放project2.DLL文件
end;
end;
end.
#########################################################################################
上面的这个调用在几十万次后,程序占的内存超大,到底是哪里的问题呢