free memory lazarus / 21-General ---------------------------------------------------------------------- 大悟还俗 · 2022-03-07 15:31 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);type  _FileRec = record    FileName: ShortString;    FileId  : UInt64;    ParentId: UInt64;    FullName: String;  end;  TFileRec =  _FileRec;  PFileRec = ^_FileRec;var  i: Integer;  pFile: PFileRec;  a: TList;begin  a:= TList.Create;  for I:=0 to 9999999 do begin      pFile := AllocMem(Sizeof(TFileRec));      pFile^.FileName := '';       pFile^.FullName := '';      pFile^.FileId   := I;      pFile^.ParentId := I+ 200;      a.Add(pFile);  end;  for I:= a.Count-1 downto 0 do begin      FreeMem(a[I]);  end;  a.Clear;  a.Free;end; 大家好,当我执行这段代码的时候,我用任务管理器上,看到内存没有回到初始状态,我想让内存回来初始状态,而不是关闭程序时才释放 Hello everyone, when I execute this code, I use the task manager and see that the memory does not return to the initial state, I want the memory to return to the initial state, instead of releasing it when the program is closed ---------------------------------------------------------------------- marcov · 2022-03-07 15:45 It is currently not possible to force this. The heapmanager keeps memory blocks around for to keep future allocations fast. In general, afaik only large blocks are returned to the OS. But the memory is free, and will be used for new allocations ---------------------------------------------------------------------- af0815 · 2022-03-07 15:47 Try to use heaptrace and find your 'features' inside of Lazarus. If your programm ask the mem-manager for memory it will borrow it from the system. If you free the memory inside your app, it will go back to the mem-manager. And the mem-manager will hold this memory for the next request. So memory will be full free'd only a the end of the program. ---------------------------------------------------------------------- 大悟还俗 · 2022-03-07 15:53 Cloud add a new parameter for compiler to really free all memory,   thanks ---------------------------------------------------------------------- winni · 2022-03-07 15:58 Quote from: 大悟还俗 on March 07, 2022, 04:53:08 pm Cloud add a new parameter for compiler to really free all memory,   thanks Hi! No - that breaks the design of the memory manager. Read the posts of marcov and af0815 again. Winni ---------------------------------------------------------------------- marcov · 2022-03-07 16:05 Memory managers are replaceable.  You can try to write a new, or  alter an existing one. ---------------------------------------------------------------------- af0815 · 2022-03-07 16:48 Instead of using AllocMem and FreeMem you can get the memory direct from/back to system. If you use it in such manner, you can controll all. ---------------------------------------------------------------------- 大悟还俗 · 2022-03-08 04:14 Thank you