Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Programming
»
General
»
free memory
Free Pascal
Website
Downloads
Wiki
Documentation
Bugtracker
Mailing List
Lazarus
Website
Downloads (Laz+FPC)
Packages (OPM)
FAQ
Wiki
Documentation (RTL/FCL/LCL)
Bugtracker
CCR Bugs
GIT
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
How to use the forum
Forum Rules
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
OpenDocument('Filename') ...
by
J-G
[
Today
at 10:40:41 am]
Freepascal
by
LeP
[
Today
at 09:40:33 am]
TTL Record Count, i.e. a ...
by
Zvoni
[
Today
at 09:10:08 am]
weird error message
by
Thaddy
[
Today
at 07:53:17 am]
Printing on HP Smart Tank
by
Thaddy
[
Today
at 07:10:37 am]
P.I.S.S. a PlugIn-framewo...
by
cdbc
[
Today
at 06:38:27 am]
MVP made easier.
by
cdbc
[
Today
at 06:18:24 am]
I have made some progress...
by
onionmixer
[
Today
at 02:57:55 am]
WASM import error
by
Fibonacci
[July 12, 2026, 09:30:47 pm]
Lazarus 4.6 may erase you...
by
Martin_fr
[July 12, 2026, 06:35:29 pm]
Best name for procedure
by
LemonParty
[July 12, 2026, 05:23:02 pm]
Fixed an RV32ec compiler ...
by
MattBradford
[July 12, 2026, 05:11:16 pm]
Many recent books on Laza...
by
Tomu
[July 12, 2026, 05:02:44 pm]
Lazarus Bugfix Release 4....
by
geraldholdsworth
[July 12, 2026, 04:35:14 pm]
International Pascal Cong...
by
zeljko
[July 12, 2026, 04:08:53 pm]
equivalent to C/C++ "offs...
by
jamie
[July 12, 2026, 02:43:16 pm]
val return code
by
ALLIGATOR
[July 12, 2026, 01:40:21 pm]
Help needed on how to do ...
by
cdbc
[July 12, 2026, 12:15:15 pm]
PascalRAL the fastest, mo...
by
Mobius1
[July 12, 2026, 11:24:00 am]
TDateTimePicker - Make th...
by
AlexanderT
[July 12, 2026, 09:57:05 am]
TCollection wiki entry
by
Thaddy
[July 12, 2026, 05:44:53 am]
UI app to work with SQLit...
by
LeP
[July 12, 2026, 12:50:04 am]
Elite Arcade
by
Guva
[July 11, 2026, 11:25:29 pm]
Why is my program freezin...
by
paweld
[July 11, 2026, 07:19:46 pm]
is there PDS reader/expor...
by
jamie
[July 11, 2026, 07:01:12 pm]
« previous
next »
Print
Pages: [
1
]
Author
Topic: free memory (Read 2898 times)
大悟还俗
Newbie
Posts: 3
free memory
«
on:
March 07, 2022, 04:31:01 pm »
Code: Pascal
[Select]
[+]
[-]
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
Logged
marcov
Administrator
Hero Member
Posts: 12944
FPC developer.
Re: free memory
«
Reply #1 on:
March 07, 2022, 04:45:12 pm »
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
Logged
af0815
Hero Member
Posts: 1409
Re: free memory
«
Reply #2 on:
March 07, 2022, 04:47:31 pm »
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.
Logged
regards
Andreas
大悟还俗
Newbie
Posts: 3
Re: free memory
«
Reply #3 on:
March 07, 2022, 04:53:08 pm »
Cloud add a new parameter for compiler to really free all memory, thanks
Logged
winni
Hero Member
Posts: 3197
Re: free memory
«
Reply #4 on:
March 07, 2022, 04:58:31 pm »
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
Logged
marcov
Administrator
Hero Member
Posts: 12944
FPC developer.
Re: free memory
«
Reply #5 on:
March 07, 2022, 05:05:11 pm »
Memory managers are replaceable. You can try to write a new, or alter an existing one.
Logged
af0815
Hero Member
Posts: 1409
Re: free memory
«
Reply #6 on:
March 07, 2022, 05:48:52 pm »
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.
Logged
regards
Andreas
大悟还俗
Newbie
Posts: 3
Re: free memory
«
Reply #7 on:
March 08, 2022, 05:14:20 am »
Thank you
Logged
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Programming
»
General
»
free memory
TinyPortal
© 2005-2018