whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

25 Visitors Online


 
...detect memory leaks?
Autor: Jochen Fromm
[ Print tip ]  

Tip Rating (19):  
     


procedure TForm.DebugProcessStatus(s: string);
var 
  
pmc: PPROCESS_MEMORY_COUNTERS;
  cb: Integer;
  MemStat: tMemoryStatus;
begin
  
MemStat.dwLength := SizeOf(MemStat);
  GlobalMemoryStatus(MemStat);

  // Get the total and available system memory
  
TotalMemoryLabel.Caption := 'Total system memory: ' +
    FormatFloat('###,###', MemStat.dwTotalPhys / 1024) + ' KByte';
  FreeMemoryLabel.Caption  := 'Free physical memory: ' +
    FormatFloat('###,###', MemStat.dwAvailPhys / 1024) + ' KByte';

  // Get the used memory for the current process
  
cb := SizeOf(TProcessMemoryCounters);
  GetMem(pmc, cb);
  pmc^.cb := cb;
  if GetProcessMemoryInfo(GetCurrentProcess(), pmc, cb) then
  begin
    
NewWorkingMemory           := Longint(pmc^.WorkingSetSize);
    ProcessMemoryLabel.Caption := 'Process-Memory: ' +
      FormatFloat('###,###', NewWorkingMemory / 1024) + ' KByte';
    MemoryLeakLabel.Caption    := 'Memory Loss: ' +
      FormatFloat('###,###', (NewWorkingMemory - OldWorkingMemory) / 1024) + ' KByte';
    OldWorkingMemory           := NewWorkingMemory;
  end;
  FreeMem(pmc);

  DebugStatusLabel.Caption := 'Status: ' + s;
end;


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners