Memory leak and Halt lazarus / 21-General ---------------------------------------------------------------------- jollytall · 2024-11-20 11:15 I have a program that basically only reads external resources (sensors and alike) and executes actions also on external devices. Inside the program there are various objects created and used without a memory leak. However sometimes external devices are lost and the program cannot work properly. The solution I found is to manually kill the program when it is noticed and as the program is a service, it can safely restart. I want to automate it and kill the program from inside if a device is lost, using Halt(error code). Now I read the user manual of Halt https://www.freepascal.org/docs- html/rtl/system/halt.html and it says that just calling Halt without proper clean-up might cause memory leak. My question, whether under Linux (but probably the same under other OSs) the OS cleans up automatically all memory that is reserved by a program? My impression so-far was that if a program terminates (not talking about dynamically linked libraries that might stay active) then the OS does all the housekeeping, so there is no need to clean all objects (yes I know it is good programming practice) before leaving. So, can there be a memory leak somehow if I just Halt the program when I feel that it cannot be repaired and need to restart? ---------------------------------------------------------------------- Thaddy · 2024-11-20 11:23 You can simply check this on linux with top: the memory is returned after the program ends even if it leaks. ---------------------------------------------------------------------- MarkMLl · 2024-11-20 11:27 I believe that the unix doctrine is to clean up all resources owned by a process, with the exception of things like the names associated with unix-domain sockets etc. which should be handled like any other file... possibly also shared memory. I suspect that the "memory might not be released" really means "...released in a controlled fashion, in the correct order". So if you were somehow able to break into the execution sequence after the Halt() you'd be likely to see an inconsistent heap. All pending confirmation by somebody who knows what he's talking about :-) MarkMLl