程序已经关闭,但在内存中没有迅速销毁(100分)

  • 主题发起人 主题发起人 flfqzrj
  • 开始时间 开始时间
F

flfqzrj

Unregistered / Unconfirmed
GUEST, unregistred user!
程序已经关闭,但在内存中没有迅速销毁,没用有第三方的控制
程序是读取定好规格的文本文件,然后在内存中排序,内容有几万条.
原程序刚运行时只有 4M多,读取文本后,有30M多,程序关闭后,看到[任务管理器]只进程,几十K几十K的减少,等到只有20多M时,才突然间消
 
突然间全部销毁.程序完全关闭
 
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls,ZT_SongSixOKDate, ComCtrls;

type
TFrm_PHMain = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
Edit_SongPATH: TEdit;
Button_RdSong: TButton;
Edit_HitsPATH: TEdit;
Button_RdHits: TButton;
StatusBarMain: TStatusBar;
ListView_Song: TListView;
ListView_Hits: TListView;
TeOpenDialog: TOpenDialog;
procedure Button_RdSongClick(Sender: TObject);
procedure Button_RdHitsClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Frm_PHMain: TFrm_PHMain;

implementation

{$R *.dfm}
var
StopFlag:Boolean;
procedure TFrm_PHMain.Button_RdSongClick(Sender: TObject);
Var
aItem: TListItem;
TS:TstringList;
iCount:integer;
StrTemp:string;
songCode:string[8];
songName:string[40];
begin
TS := TStringList.Create;
aItem:=TListItem.Create(nil);
TeOpenDialog.Filter:='song.dat|song.dat';
if TeOpenDialog.Execute then
Edit_SongPATH.Text :=TeOpenDialog.FileName;

if FileExists(Edit_SongPATH.Text) then
Begin
TS.LoadFromFile(TeOpenDialog.FileName );
TS.Sort ;//排序
Application.ProcessMessages ; //交处理权给系统
StatusBarMain.Panels[2].Text :='共需处理:'+inttostr(ts.Count -1)+' 首歌';
for iCount:=1 to ts.Count -1 DO
Begin
if StopFlag then
Begin
aItem.Free ;
TS.Free ;
exit;
End;
StrTemp:=TS.Strings[icount];
//songCode:=Copy(StrTemp,0,8);
songCode:= StrTemp;
//SongName:=trimright(Copy(StrTemp,9,40)) ;
delete(StrTemp,1,8);
SongName:=trimright(StrTemp);
ZT_SongSixOKDate.IniSongInfoIncrement(songCode,SongName);
aItem:=ListView_Song.Items.Add ;
aItem.Caption :=songCode;
aItem.SubItems.Append(SongName);
Application.ProcessMessages ; //交处理权给系统
StatusBarMain.Panels[3].Text :='已经处理了:'+inttostr(iCount) + ' 首歌';
End;

aItem.Free ;
end;
TS.Free ;
end;

procedure TFrm_PHMain.Button_RdHitsClick(Sender: TObject);
Var
aItem: TListItem;
TS:TstringList;
iCount:integer;
StrTemp:string;
SONGCode:string[8];
SongNB:STRING[5];
intSongInfoIndex:integer;
begin
TS:=TstringList.Create ;
aItem:=TListItem.Create(nil);
TeOpenDialog.Filter:='hits.dat|hits.dat';
if TeOpenDialog.Execute then
Edit_HitsPATH.Text :=TeOpenDialog.FileName;

if FileExists(Edit_HitsPath.Text) then
Begin
TS.LoadFromFile(TeOpenDialog.FileName );
StatusBarMain.Panels[0].Text :='排行歌曲共有:'+inttostr(ts.Count -1);
for iCount:=1 to ts.Count -1 DO
Begin
if StopFlag then
Begin
aItem.Free ;
TS.Free ;
exit;
End;
StrTemp:=TS.Strings[icount];
aItem:=ListView_Hits.Items.Add ;
aItem.Caption :=inttostr(iCount);
SONGCode :=StrTemp;
Delete(strTemp,1,9);
SongNb:=strtemp;
aItem.SubItems.Append(SONGCode);
intSongInfoIndex:=ZT_SongSixOkDate.IndexOfSongInfoByZB(SONGCode);
if intSongInfoIndex<>-1 then
aItem.SubItems.Append(PSongInfo(SongInfoList.Items[intSongInfoIndex]).Name)
Else
aItem.SubItems.Append('歌名没有查到');
//aItem.SubItems.Append('歌名待查');
//aItem.SubItems.Append('歌名待查');
//aItem.SubItems.Append(copy(StrTemp,Pos(',',StrTemp)+1,(length(StrTemp)-Pos(',',StrTemp))) );
aItem.SubItems.Append(SongNb);
Application.ProcessMessages ; //交处理权给系统
StatusBarMain.Panels[1].Text :='已经处理了:'+inttostr(iCount);
End;
End;

aItem.Free ;
TS.Free ;
end;

procedure TFrm_PHMain.FormCreate(Sender: TObject);
begin
SongInfoList:=TList.Create ;
StopFlag:=False;
end;

procedure TFrm_PHMain.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
StopFlag:=True;
//Application.ProcessMessages ; //交处理权给系统
//sleep(500);
Application.ProcessMessages ; //交处理权给系统
SongInfoList.Clear ;
SongInfoList.Free ;
//repeat
//sleep(500);
//Application.ProcessMessages ; //交处理权给系统
//until not Assigned(SongInfoList) ;
end;

end.
 
unit ZT_SongSixOKDate;

interface
Uses
Windows, Classes,SysUtils, Controls;
Type
PSongInfo=^SongInfo ;
SongInfo=Record
Code:string[8];
Name:string[40];
End;

Var
SongInfoList:TList;

function IndexOfSongInfo(Code:String; AList:TList): integer; overload;
function IndexOfSongInfo(Code:String): integer; overload;
function IndexOfSongInfoByZB(Code:String; AList:TList): integer; overload;
function IndexOfSongInfoByZB(Code:String): integer; overload;
function SongInfoDecrement(Code:String): integer;
function SongInfoIncrement(Code,SongName:String): integer;
//初始化数据库
function IniSongInfoIncrement(Code,SongName:String): integer;
implementation



function IndexOfSongInfo(Code:String; AList:TList): integer; overload;
begin
Result := 0;
while (Result < AList.Count) and (PSongInfo(AList.Items[Result]).Code <> Code) do
Inc(Result);
if Result = AList.Count then
Result := -1;
end;


function IndexOfSongInfo(Code:String): integer; overload;
begin
Result := IndexOfSongInfo(Code,SongInfoList);
end;

//********************* 折半查找**********************
function IndexOfSongInfoByZB(Code:String): integer; overload;
begin
Result := IndexOfSongInfoByZB(Code,SongInfoList);
end;

function IndexOfSongInfoByZB(Code:String; AList:TList): integer; overload;
var
L,R,M:Integer;
sCode:integer;
begin
Result := -1;
sCode:=Strtointdef(Code,-1);
if AList.Count=0 then exit;
L:=0;
R:= AList.Count;
While (L<=R) DO
Begin
M:=(l+r) div 2;
if STRTOINTdef(PSongInfo(AList.Items[M]).Code,-1)= sCode then
Begin
Result:=M;
Exit;
End;
if STRTOINTdef(PSongInfo(AList.Items[M]).Code,-1)< sCode then L:=M+1;
if STRTOINTdef(PSongInfo(AList.Items[M]).Code,-1)> sCode then R:=M-1;
End;
end;
//******************************************


function SongInfoDecrement(Code:String): integer;
var
intSongInfoIndex:integer;
_PSongInfo:PSongInfo;
begin
Result:=-1;

intSongInfoIndex:= IndexOfSongInfo(Code);
if intSongInfoIndex<>-1 then
begin
_PSongInfo:=PSongInfo(SongInfoList.Items[intSongInfoIndex]);
Dispose(_PSongInfo);
SongInfoList.Delete(intSongInfoIndex);
Result:=intSongInfoIndex;

end;
end;

//初始化数据库
function IniSongInfoIncrement(Code,SongName:String): integer;
var
_PSongInfo:PSongInfo;
begin

Result:=0;
New(_PSongInfo);
_PSongInfo.Code := Code;
_PsongInfo.Name := SongName;
SongInfoList.Add(_PSongInfo);
end;

function SongInfoIncrement(Code,SongName:String): integer;
var
intSongInfoIndex:integer;
_PSongInfo:PSongInfo;
begin

Result:=0;

intSongInfoIndex:= IndexOfSongInfo(Code);
if intSongInfoIndex=-1 then
begin
New(_PSongInfo);
_PSongInfo.Code := Code;
_PsongInfo.Name := SongName;
SongInfoList.Add(_PSongInfo);
end;
end;
end.
 
慢慢的会自己消毁
 
毁尸灭迹也要点时间的吧
 
有多慢??一秒算不算慢?
 
大约要20多秒吧,不过也太慢了吧!从37M到20M这时候慢,20M以后一秒就行了
 
既然能如数释放,应该是操作系统的内存调度问题吧。
 
20多秒是比较慢.
不过你可以在关闭程序的同时隐藏程序界面,比如mainform.top:=-2000.这样可以给客户一个关闭很快的错觉.
 
直接来Application.Termate;比较爽吧.
 
Application.Termate;
会不会使内存里本程序原先占用的内存占着不放??
 
后退
顶部