Here are some of the different "memories" you can learn to develop:* Muscle memory - the most basic and unreliable one IMO. Comes with repeating your piece over and over until playing the notes is automatic.* Aural memory - remembering how the piece goes, helping you know or at least make an educated guess on what key to press based on what sounds are supposed to come next. Improves as your ear training improves. Easier if you have perfect pitch.* Visual memory - a big one for me. Involves remembering how it looks when my hands are playing the right chords or passages. You kind of look at the keyboard and know where and how to place your hands next.* Sheet music memory - remembering how the score looks so that you can recall the score, read and play it from your mind, so to speak.* Music theory memory - this one is huge and can get quite advanced. Even if you just start getting into the basics it can help you a lot. Involves a number of subskills such as** Basic chords and scales - remembering everything you plays in terms of what basic chords and scales are used, and any deviations therefrom. Helps you remember big chunks of music because a bar suddenly becomes "A c major scale in sixteenths for three beats" rather than 12 individual keys presses to remember, or "an A flat major arpeggio with a B natural thrown in along the way".** Harmonic functions and common chord progressions - helps you remember longer sequences or make educated guesses on what to play next because you know all the common patterns and have identified which one is being used at a given moment. So even if you have forgotten the exact notes, if you know that "here comes the dominant followed by the tonic in A flat major" you can play something that's reasonable and at least continue playing without interruption if you forget the exact notes. And knowing that "this is this common chord progression realized in this particular way" helps a lot with remembering a passage because you have a logical structure to connect what you are doing to. Everything that helps me understand something as a part of a larger pattern helps me remember it.** Voice leading - again helps you understand and make educated guesses on why particular notes were chosen by the composer to come next in many cases.
You must be able to hear what it should sound like without the need to physically play it, the sound in your minds eye must capture all the notes and expect to hear it, any errors would be corrected by your ear or understood as being wrong because it is not what you expect to hear.