I use many techniques for memorising, including learning to sing the melody line - remembering the chord/harmonic sequence - playing the passage a million times etc. All of these give some success, but the one thing that never fails me (and sadly I never do this until all others have failed
) is to copy out the passage on manuscript paper, repeatedly, until I can write it from memory. Time consuming but, for me, almost infallible. When I can write without error, I can play without hesitation.
Another technique I use with my younger pupils is to coach them into visualising their hand movements on the strings - without moving the hands or holding the guitar - until they can "see" the correct sequence of movements and describe them to me accurately. Usually when they acheive this they can then play through the passage, slowly, with confidence. The passage needs to be short but we frequently manage 16 bars in one lesson. Strangely, I find few pupils over the age of about 12 who can "visualise" clearly enough to use this method.
I have often used the last few minutes before falling asleep at night to calmly think through a troublesome passage.
At times, having my hands on the guitar prevents me from processing clearly.
Sorry if this seems confusing. I am just typing as I am thinking it through.
If age is significant, I am 76. What I describe still works for me.
Best of luck
If you don't grow up, you'll never grow old.