There is another aspect of memorization that I'd like to bring up. It reinforces some of the comments by Robert Henry, and is based upon my instructor's directions and the material in books written by Lhevinne, Giesking, Hoffmann, and others. I'll use Beethoven's Sonata #15 , Op. 28, in D-major, the 'Pastorale' sonata, as an example.
For the past 6 months or so I've been learning and memorizing the sonata, to bring it to performance level. At this point I can play the entire sonata by memory, I can start anywhere in the piece that I like, I can play many passages backwards and forwards (this is a good exercise), I can play the piece staccato, legato, forte, piano, with and without pedal, and almost any other way you can imagine. I can play it in my sleep!! My instructor will often sit me down at the piano, pick a bar from somewhere in the sonata, and say 'play it'. If you can do this then you have really memorized the piece.
Now, I don't have a photographic memory and there is no magic here. One thing that I do is analyze the piece at the piano and away from the piano. First, what key is it in at the start (D-major) and where are the major key changes? I note these in the score. What meter is each movement in and are there any changes? I note these in the score. What are the harmonic relationships in the piece (tonic, dominant, subdominant, etc.). I also note these in the score. What is the larger structure of the piece? AABA, ABA, etc.
Here are some examples:
1) The first movement starts in D-major. So I've been practicing the D-major scale like mad - arpeggios, broken octaves, rhythms, etc. This really helps with fingering and fixes the D-major scale in your mind. The first note of the sonata is low D. You might forget this if you're nervous on stage! But if you remember 'This sonata is in D-major' that low D note springs to mind.
2) The dominant of D-major is A-major. There are numerous points in the sonata where it modulates to A-major. For example, in bar 129 of the first movement. Every time I reach this point in the piece I think to myself 'We're now in A-major' and the A-major scale, fingerings, etc. come to mind. There are several bars of A-major chords and their inversions. If I forget where I am at this point, the A-major scale and its diatonic chords and inversions come to mind, which helps me remember these bars.
3) The subdominant of D-major is G-major. At bar 165 in the first movement there is a modulation to G-major. Every time I play the preceeding four bars I think to myself 'Here comes G-major, the subdominant of D'. Sometimes, even though I've played this piece hundreds of times now, my finger memory fails me. I reach this point in the sonata and cannot quickly remember where my fingers should go. Just tired or nervous I guess. However, instantly the thought of 'G-major subdominant of D' comes to mind and I recover and play just fine.
4) Beginning at bar 217 of the first movement it modulates to (mostly) F-sharp major (and minor) and stays there for about 36 bars. Whenever I play this part I think 'This is in F-sharp major (minor)'. So even if my finger memory fails, I think instead about F-sharp scales and chords. After a half-bar or so my finger memory returns and everything is OK.
5) The first movement of this sonata is in AABA form. The exposition (A) ends around bar 161, the development (B) is in bars 162 - 266, and the recapitulation is the remaining bars. Knowing this larger structure gives me a broad mental picture of the piece. This also helps with memorization because you always know where you are in the sonata relative to other sections.
6) I analyzed the second, third, and fourth movements in the same way - in great detail. It really helps with memorization.
Finally, analyzing a piece like this is really enjoyable. It gives you a deeper understanding of how the composer constructed music and how all the parts relate to one another. Hope this helps some of you with memorization.