I only know a little bit about coding, but if I had to guess it creates a file or sth like that, and when you get to a point where the memory would trigger a different path it runs an If-clause (If Memory 1 exists, then, otherwise) and continues based on that.
I've never used RenPy and I only had a few years of basic coding in school so this may not be 100% accurate but that's how I'd code it