In Settings > Advanced > Recording > Filename Formatting you're able to change the name template. OBS is creating a name from this template, usually including date and time info, and starts writing to this file as soon as you start recording. OBS finalizes and closes the file when you stop the recording. OBS doesn't keep a recording in memory and saves that to disk, it's directly writing to the file.
Exception is the replay buffer, where it writes the content of the replay buffer in one take. This function also uses the name template from the above mentioned location.