On Mon, Sep 23, 2024 at 9:21 AM Chris Bennett < cpb_m...@bennettconstruction.us> wrote:
> So if I run small program A that has some leaks. I don't free a few > things as suggested. Then I run program B that happens to use those > memory addresses that didn't get freed by program A, what happens then? > Are there problems? Or does it just get used properly? > Mostly, things work properly. But 'how' properly depends on the details. If program A terminates, then any resources it didn't explicitly free will be freed automatically and those resources will then be available for re-use. If program A hangs, or sleeps, or spawns B and waits for it to terminate, then the resources A holds won't be released. If program A doesn't run then eventually any memory it holds will be paged out so those pages can be reused by actively running processes, assuming you have swap space. The scenario you give, where B wants to use memory still in use by A, doesn't really happen because A and B each get their own separate virtual address spaces. The same address in A will refer to a different physical page than that same address in B, and the OS will ensure that the physical pages are not shared inappropriately. -ken