有没有检查delphi程序存储空间泄漏的软件

已举报 回答
有没有检查delphi程序存储空间泄漏的软件
问在线客服
扫码问在线客服
  • 回答数

    8

  • 浏览数

    1,213

8个回答 默认排序
  • 默认排序
  • 按时间排序

已采纳
Delphi 2007 下面,在主窗口的 FormCreate 加一条
ReportMemoryLeaksOnShutdown:=true;
有内存泄漏,会弹出一个对话框.
CheckMem检测程序的内存泄漏 ,使用方法很简单,把 CHECKMem.pas 加到工程代码的第一行,重新编译程序.
再运行exe文件 . 有内存泄漏在本目录下 生成 CheckMemory.Log文件.
CheckMem.pas
unit CheckMem; //Add it to the first line of project uses
interface
procedure SnapCurrMemStatToFile(Filename: string);
implementation
uses
Windows, SysUtils, TypInfo;
const
MaxCount = High(Word);
var
OldMemMgr: TMemoryManager;
ObjList: array[0..MaxCount] of Pointer;
FreeInList: Integer = 0;
GetMemCount: Integer = 0;
FreeMemCount: Integer = 0;
ReallocMemCount: Integer = 0;
procedure AddToList(P: Pointer);
begin
if FreeInList High(ObjList) then
begin
MessageBox(0, '内存管理监视器指针列表溢出,请增大列表项数!', '内存管理监视器', mb_ok);
Exit;
end;
ObjList[FreeInList] := P;
Inc(FreeInList);
end;
procedure RemoveFromList(P: Pointer);
var
I: Integer;
begin
for I := 0 to FreeInList - 1 do
if ObjList[I] = P then
begin
Dec(FreeInList);
Move(ObjList[I + 1], ObjList[I], (FreeInList - I) * SizeOf(Pointer));
Exit;
end;
end;
procedure SnapCurrMemStatToFile(Filename: string);
const
FIELD_WIDTH = 20;
var
OutFile: TextFile;
I, CurrFree, BlockSize: Integer;
HeapStatus: THeapStatus;
Item: TObject;
ptd: PTypeData;
ppi: PPropInfo;
procedure Output(Text: string; Value: integer);
begin
Writeln(OutFile, Text: FIELD_WIDTH, Value div 1024, ' KB(', Value, ' Byte)');
end;
begin
AssignFile(OutFile, Filename);
try
if FileExists(Filename) then
begin
Append(OutFile);
Writeln(OutFile);
end
else
Rewrite(OutFile);
CurrFree := FreeInList;
HeapStatus := GetHeapStatus; { 局部堆状态 }
with HeapStatus do
begin
Writeln(OutFile, '===== ', ExtractFileName(ParamStr(0)), ',', DateTimeToStr(Now), ' =====');
Writeln(OutFile);
Output('可用地址空间 : ', TotalAddrSpace);
Output('未提交部分 : ', TotalUncommitted);
Output('已提交部分 : ', TotalCommitted);
Output('空闲部分 : ', TotalFree);
Output('已分配部分 : ', TotalAllocated);
Output('全部小空闲内存块 : ', FreeSmall);
Output('全部大空闲内存块 : ', FreeBig);
Output('其它未用内存块 : ', Unused);
Output('内存管理器消耗 : ', Overhead);
Writeln(OutFile, '地址空间载入 : ': FIELD_WIDTH, TotalAllocated div (TotalAddrSpace div 100), '%');
end;
Writeln(OutFile);
Writeln(OutFile, Format('当前出现 %d 处内存漏洞 :', [GetMemCount - FreeMemCount]));
for I := 0 to CurrFree - 1 do
begin
Write(OutFile, I: 4, ') ', IntToHex(Cardinal(ObjList[I]), 16), ' - ');
BlockSize := PDWORD(DWORD(ObjList[I]) - 4)^;
Write(OutFile, BlockSize: 4, '($' + IntToHex(BlockSize, 4) + ')字节', ' - ');
try
Item := TObject(ObjList[I]);
if PTypeInfo(Item.ClassInfo).Kind tkClass then { type info technique }
write(OutFile, '不是对象')
else
begin
ptd := GetTypeData(PTypeInfo(Item.ClassInfo));
ppi := GetPropInfo(PTypeInfo(Item.ClassInfo), 'Name'); { 如果是TComponent }
if ppi nil then
begin
write(OutFile, GetStrProp(Item, ppi));
write(OutFile, ' : ');
end
else
write(OutFile, '(未命名): ');
Write(OutFile, Item.ClassName, ' (', ptd.ClassType.InstanceSize,
' 字节) - In ', ptd.UnitName, '.pas');
end
except
on Exception do
write(OutFile, '不是对象');
end;
writeln(OutFile);
end;
finally
CloseFile(OutFile);
end;
end;
function NewGetMem(Size: Integer): Pointer;
begin
Inc(GetMemCount);
Result := OldMemMgr.GetMem(Size);
AddToList(Result);
end;
function NewFreeMem(P: Pointer): Integer;
begin
Inc(FreeMemCount);
Result := OldMemMgr.FreeMem(P);
RemoveFromList(P);
end;
function NewReallocMem(P: Pointer; Size: Integer): Pointer;
begin
Inc(ReallocMemCount);
Result := OldMemMgr.ReallocMem(P, Size);
RemoveFromList(P);
AddToList(Result);
end;
const
NewMemMgr: TMemoryManager = (
GetMem: NewGetMem;
FreeMem: NewFreeMem;
ReallocMem: NewReallocMem);
initialization
GetMemoryManager(OldMemMgr);
SetMemoryManager(NewMemMgr);
finalization
SetMemoryManager(OldMemMgr);
if (GetMemCount - FreeMemCount) 0 then
SnapCurrMemStatToFile(ExtractFileDir(ParamStr(0)) + 'CheckMemory.Log');
end.
取消 评论
CPU,内存有故障电脑开不了机,频繁报错的现象。硬盘有专们的软件可以测试。百度搜索一下有很多
取消 评论
1、很有可能,关键性的系统文件遭到了破坏。如果有系统盘,可以使用 sfc 命令来修复。
2、用360安全卫士等软件、杀毒软件扫描。
3、最彻底的解决方法是重新做系统。
取消 评论
没有这种软件啊。。我也在找。
取消 评论
然而正当关羽带伤与徐晃交战的同时,东吴陆逊巧妙利用关羽骄傲自满、刚愎自用的心理,定下了取荆州之计。吕蒙白衣渡江,袭了荆州。痛失荆州的关羽被迫败走麦城,终为吕蒙部下所害。在玉泉山,关羽灵魂显圣,为神僧普净点化而顿悟,飘然离去。不久吕蒙被关羽附体而亡(此时为建安二十四年,即公元219年)。[1] 孙权将关羽首级献于曹操,曹操为关羽吓倒,自此便寝食不安。为建新宫,曹操持剑去砍洛阳城内一神树,树干喷出血来,病情加重,危在旦夕。曹操令人找来神医华佗,却疑之有害己之意而将其拷打至死。建安二十五年(220年),曹操病逝于洛阳。[1]
取消 评论
能进入系统,就说明没什么问题了,再有问题就拆开机箱看各部件的发热了,如果发热量很大说明质量不好。
取消 评论
你把随机启动的程序都清了,然后看看有没这个现象
一般来说,软件问题居多。
先完全卸载网卡驱动,然后重装一下网卡驱动!~最新的
取消 评论
重启电脑
取消 评论
ZOL问答 > 有没有检查delphi程序存储空间泄漏的软件

举报

感谢您为社区的和谐贡献力量请选择举报类型

举报成功

经过核实后将会做出处理
感谢您为社区和谐做出贡献

扫码参与新品0元试用
晒单、顶楼豪礼等你拿

扫一扫,关注我们
提示

确定要取消此次报名,退出该活动?