我写一个调用DLL窗体的程序,DLL中包括一个FORM和一个datamodule.
当我调用DLL窗体,操作完毕并关闭DLL窗体后,程序占用的内存无法恢复到程序刚运行时占用的大小;
而且,每调用一次DLL窗体,占用的内存都会增加一点,这样下去系统资源起不是要被用光了.大家帮我看下,程序如下:
library dll;uses
  SysUtils,
  Classes,
  Activex,
  dllu in 'dllu.pas' {Form2},
  dlldatemd in 'dlldatemd.pas' {DataModule1: TDataModule};{$R *.res}procedure showform(); stdcall;
begin
   Form2:=TForm2.Create(nil);
   Form2.ShowModal;
   Form2.Free;
end;exports
  showform;begin
   CoInitialize(nil);
   DataModule1:=TDataModule1.Create(nil); 
end.--------------------------------------------------------------
unit mainu;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;
 
implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
  aptr:procedure ;stdcall;
  LibHandle: THandle;
begin
 // showform;
   LibHandle := LoadLibrary('dll.dll');
   aptr:=GetprocAddress(LibHandle,'showform');
   if @aptr<>nil then aptr;
   FreeLibrary(LibHandle);
end;end.

解决方案 »

  1.   

    你调用的时候每个LOADLIBRARY都要对应一个FREELIBRARY来释放资源~
      

  2.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, Grids, DBGrids, StdCtrls, Buttons,ActiveX;type
      TForm1 = class(TForm)
        DBGrid1: TDBGrid;
        BitBtn1: TBitBtn;
        procedure BitBtn1Click(Sender: TObject);
        procedure FormShow(Sender: TObject);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
         LinkMode:String;
           Apps:variant;
      end;var
      Form1: TForm1;   procedure showform;export;
        Function GetRegInfo(Flag:Integer):ShortString;external 'OPUHIS.DLL';
    implementationuses Unit2;{$R *.dfm}
    procedure showform;
    begin
      CoInitialize(Nil);
      DataModule2 := TDataModule2.Create(Application);
      Form1:=TForm1.Create(Application);
      with Form1 do begin
         ShowModal;
         CoUnInitialize;
         DataModule2.Free;
         Free;
      end;
    end;
    调用:
    procedure TForm1.Button1Click(Sender: TObject);
    var
      Sabout:THandle;
      ShowA:procedure;
    begin
       KillDll('Project1.dll');
       Sabout := LoadLibrary('Project1.dll');
      if  Sabout=0 then begin
        Application.MessageBox('动态连接库Project1.dll文件不存在!','错误',64);
        exit;
       end;
       ShowA := GetProcAddress(Sabout,'showform');
       showA;
       FreeLibrary(Sabout);
    end;
      

  3.   

    begin
       CoInitialize(nil);
       DataModule1:=TDataModule1.Create(nil); 
    end.
    你的dll工程文件中建立了一个数据模块窗体,但没有释放他,将他释放试试