Some musicians I know say that to really learn a piece of music, you have to first learn by heart, then forget it, learn it by heart again, forget it again and then the third time, it's finally there.
Memorisation is hardly a musicians-only problem and there are lots of good techniques and tips to be found on the internet and elsewhere. What they all have in common, is that they are based on association because that how our memory works. Our brains don't handle free standing pieces of info very well, it wants connections. Every new thing we remember is based on and connected to some memory already stored there. The brain is also very good at handling patterns so the better you can systemitize the info, the easier it is to remember.
I could write a book about this - or at least a long article - but a few tips will have to do for now:
- Find the chord shapes. It's amazing how much guitar music, even the most polyphonic and/or atonal is based on the standard chord shapes. They may be modified and well hidden but they are still there and can be good "hooks" to hang your music on.
- Remember the scales. What is easiest, to remember the notes C-D-E-F-G-A-B-c or to remember it's a C major scale over one octave?
- Find patterns. Like this: C-E-D-F-E-G-F-A-G-B-A-d-c. hard to remember? Just think "two up, one down".
- Focus on the end result more than the method. How does the music sound? If you have a clear idea of that, your fingers will find it much easier to remember how to play it.
- Visualize. There's a really good trick I learned from John Mills. He said he always had a picture in his mind when he played, some imaginary or remembered scene that fit the mood of the music. This is mainly to help interpretation but it's also very useful for memorisation - one more strong hook to help your brain fix the memory in place.