We remember those moments with shame because we keep reliving them and reveling in the shame.
Remembering something taints the memory with your current mindset.
When those memories come up, choose a different response. Laugh at yourself. Forgive yourself. Love yourself.
Those memories will change in response when you stop the self-abuse. And it really does feel better too.
Here is an article discussing it.
I would personally think that Buddhist techniques like mindfulness and meditation would be helpful here.
I don’t know how I really achieved it, but one thing I do remember I did was altering my negative self-talk so I would be alarmed and notice I was doing it.
I basically changed “I should kill myself” to “I should kill (some other specific person)”, as the latter horrified me. Might be a similar technique.