Two things.
First, correctly shutdown requires work to be done. Just removing things from memory is fast. If you tell a program to close, it will likely have to do some tidying up before closing
Second, there are mechanisms to offload some memory to disk (swap and pagination are the terms to lookup), this exists because memory is limited and usually you have way more disk space. When your pc memory is filling up, the OS will store some of that in the hard drive (wich is slower) and it need to access it later, when you close a program that hasn’t been used for some time, the OS first needs to load the memory from disk and then close the program
Latest Answers