Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy doesn't my program's memory usage return to normal after I free memory?
    primarykey
    data
    text
    <p>consider the next sample application</p> <pre><code>program TestMemory; {$APPTYPE CONSOLE} uses PsAPI, Windows, SysUtils; function GetUsedMemoryFastMem: cardinal; var st: TMemoryManagerState; sb: TSmallBlockTypeState; begin GetMemoryManagerState(st); result := st.TotalAllocatedMediumBlockSize + st.TotalAllocatedLargeBlockSize; for sb in st.SmallBlockTypeStates do begin result := result + sb.UseableBlockSize * sb.AllocatedBlockCount; end; end; function GetUsedMemoryWindows: longint; var ProcessMemoryCounters: TProcessMemoryCounters; begin Result:=0; ProcessMemoryCounters.cb := SizeOf(TProcessMemoryCounters); if GetProcessMemoryInfo(GetCurrentProcess(), @ProcessMemoryCounters, ProcessMemoryCounters.cb) then Result:= ProcessMemoryCounters.WorkingSetSize else RaiseLastOSError; end; procedure Test; const Size = 1024*1024; var P : Pointer; begin GetMem(P,Size); Writeln('Inside'); Writeln('FastMem '+FormatFloat('#,', GetUsedMemoryFastMem)); Writeln('Windows '+FormatFloat('#,', GetUsedMemoryWindows)); Writeln(''); FreeMem(P); end; begin Writeln('Before'); Writeln('FastMem '+FormatFloat('#,', GetUsedMemoryFastMem)); Writeln('Windows '+FormatFloat('#,', GetUsedMemoryWindows)); Writeln(''); Test; Writeln('After'); Writeln('FastMem '+FormatFloat('#,', GetUsedMemoryFastMem)); Writeln('Windows '+FormatFloat('#,', GetUsedMemoryWindows)); Writeln(''); Readln; end. </code></pre> <p>the results returned by the app are </p> <pre><code>Before FastMem 1.844 Windows 3.633.152 Inside FastMem 1.050.612 Windows 3.637.248 After FastMem 2.036 Windows 3.633.152 </code></pre> <p>I wanna know why the results of the memory usage are different in the <code>Before</code> and <code>After</code>:</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload