Congruent Memory

Congruent memory (also called state-dependent learning according to The Other Wiki) is the idea that someone who learns something in a certain environment or emotional or physical state is more likely to remember what they've learned when in that same state. For example, if a rat learns its way through a certain maze while drugged, it may be able to run the maze only while drugged -- or if you study for your math test while listening to a certain song, you may be more likely to remember the formulae when listening to that song.

When this phenomenon shows up in fiction, it's often played for comedy: Usually a character will have to precisely replicate the circumstances in which he or she learned something in order to be able to recall it, or the circumstances themselves will be somewhat bizarre (or both).

Obviously Reality Is Unrealistic, because while this is a legitimate idea in modern psychology, it's never taken to the absurd levels that fiction shows.

Anime & Manga

 * Tatewaki Kunô and his watermelon training in Ranma ½.
 * In book 9 of the Girls Bravo manga, Lethal Chef Kirie is taught how to cook properly by Fukuyama. Problem, since he's a Lovable Sex Maniac, he forces her to do so while wearing a Hadaka Apron. In the end, Kirie can only cook edible stuff while nude under her apron.

Comics -- Books

 * Archie Comics
 * There was one Betty and Veronica comic where Veronica was studying for a test while lying on the floor of her room. When the day of the test came around, she couldn't remember any of the information -- until she lay down on the floor of the classroom in the same position she'd studied in.
 * In another Archie Comics story, Jughead could throw snowballs easily, but couldn't get the same feeling when handling a normal baseball.
 * In the same vein, Jughead was once scouted for the opera thanks to his bombastic singing voice -- unfortunately, he only sang well in enclosed spaces because he did most of his singing in the bath tub.

Films -- Live-Action

 * Used almost by name (Fink calls it his "theory of Drunken Recall") in Beerfest. Jan Wolfhouse has to get utterly plastered to recall how to get to the secret underground beer-drinking contest.
 * In Iron Eagle, Doug Masters learned to fly in an F16 simulator, while listening to his favourite rock tunes on his Walkman. Turns out that as long as he's got his music to listen to, he's a great pilot; without the music, he sucks.
 * In Akeelah and the Bee, Akeelah practices spelling while jumping rope. During the spelling bee, she has to jump to remember a particularly difficult word.

Literature

 * In the Robert A. Heinlein novel Glory Road, when Rufo gives Oscar a shave, he tells him he can't shave someone who's sitting up because he learned shaving by preparing corpses for burial.
 * One of the pieces in Douglas Adams' The Salmon of Doubt says this is why you can't remember your New Year's resolutions. When you write them and put them away, you're in a post-party state: stuffed, hungover, dehydrated, possibly ashamed. Once you're back to normal, you forget them until the next time you're in the same state, next New Year's Day.
 * Marcel Proust's mammoth novel Remembrance of Things Past is centered on the flood of memories triggered by the scent of a madeleine (a particular kind of cookie).
 * In The Ghost Brigades, the character Jared is a failed copy of the main villain who gradually recovers the villain's memories over the course of the book, triggered by congruent experiences. The first time it happens involves food, causing another character to namecheck Remembrance of Things Past.
 * Cam Jansen, a girl detective from a series of kids' books, says "Click!" when hunting for clues, then later repeats it to help herself remember the details of what she saw. This is explained as her having a "photographic memory," but is closer to this trope in practice.
 * Because "Cam" is short for "Camera", see?
 * In the tale of Ali-Baba and the Forty Thieves from Arabian Nights, a tailor is blindfolded and led to a certain house where the protagonist is hiding. When Ali-Baba's men try to discover the house, they blindfold the tailor and he is able to find it again.

Live-Action TV

 * In Friends, Joey practices for a commercial by repeating, "Mmmm, soup," while eating tomato soup. When auditioning for the commercial, they use a bowl of noodle soup and he is unable to get the simple "Mmmm, soup" line right.
 * Malcolm in the Middle
 * In an episode, Hal goes bowling and gets a strike every time. As the episode goes on, he develops an increasingly elaborate routine for throwing the ball, to the extent that toward the end, Hal refuses to let one of his observers go to the bathroom.
 * There was another episode where Francis teaches Otto to waltz, to surprise Gretchen on their anniversary. But when the moment comes, Otto fails miserably. He comes to realize he could only waltz with Francis.
 * Played for a non-comedic (although somewhat absurd) bent in the Season 4 finale episodes of House, where the good doctor tries to fight the amnesia that is crippling his ability to diagnose what may be afflicting victims of a bus crash he just survived. Ultimately subverted in that he chooses to just fry his frontal lobe with electricity to induce the memories.
 * In Heroes, initially Isaac Mendez could only use his precognition powers while drugged on heroin. However, he later learned how to use them without it. And since everyone else who's acquired that power since has been perfectly able to use it straight away, one suspects it was a Magic Feather. A different character has a similar problem with alcohol.
 * In the "Get Down, Study-udy-udy" episode of Hannah Montana, Miley creates a song and dance to help her remember all 206 bones in the human body. On the day of the test, she can't remember them because she can't dance and sing.
 * On Fringe, Walter Bishop frequently requests different foods while recreating his old experiments; his son Peter explains to Agent Dunham that he's trying to recover his memories. Often these food requests are for commercial food products that are no longer in production, leading to Walter purchasing multiple brands trying to find the one that comes closest.
 * One episode of Dharma and Greg features Larry, Dharma's post-hippy memory trainwreck father, regaining his memory every time he smells Hai Karate.
 * In the MASH episode where Father Mulcahy is volunteered to race the 8063's chaplain for charity, Mulcahy's training sequence includes jump rope. It wouldn't be odd if he didn't have to do it to a schoolyard rhyme.

Web Comics

 * Tedd of El Goonish Shive is better at cooking when female. He is, however, fully aware at how absurd this is. (The gender bending part, not congruent memory as a whole.) This doesn't stop him in the slightest.
 * In Funny Farm, Ront's brother Pom keeps failing tests due to being Distracted by the Sexy. Ront creates a revision technique where he associates what he needs to learn with the female anatomy. This works fine, except after the test Pom finds it also works backwards and he can't stop thinking about his schoolwork when admiring a woman.

Web Original

 * In Red vs. Blue, Donut tries to recount to Grif the things he did during the day that led to him losing an important part for Simmons' cyborg operation. Among these steps was him asking himself where he could hang out with no pants on.

Western Animation

 * SpongeBob SquarePants: "Be the crane!"
 * SpongeBob practices driving while blindfolded. When it comes time for him to take his driving test, he finds he can't drive without the blindfold. Oddly this one provides a justification: when he can see what he's doing, it terrifies him.
 * Another episode had him forget where he put his nametag. So he repeats his morning routine ad infinitum, exactly, until he remembers.
 * In an episode of Arthur, Arthur practices for a spelling bee by singing the word "aardvark". Then, when the time comes to spell the word for the bee, he does the same little song.
 * Possibly Truth in Television for anyone who has ever tried to remember the order of the alphabet, and sung the Alphabet Song. Or who find themselves singing the Preamble to the US Constitution. (Note: the song does omit part of one line to scan better...)
 * In Family Guy, Peter could play the piano only when plastered. However, it wasn't a straight example of this trope. They didn't suggest this idiosyncrasy was because he learned to play the piano while drunk. Instead, apparently without learning to play or practicing beforehand, he just inexplicably developed a talent for playing the piano that required him to be drunk.
 * On Hey Arnold, Grandpa learned to play golf by watching a video presented in rhyme. He could then only hit the ball correctly if he first recited one of the rhymes. When he came to a particularly daunting hole that the video didn't cover, he made up his own rhyme, and was still successful.
 * Averted on South Park: Towelie claims that, since he was high when he learned the passcode to enter the secret government base, he needs to get high in order to remember it. Once he does get high, all he manages to do is pound on the front door keypad to reproduce the Epic Riff from "Funkytown".
 * Played straight in an episode of The Flintstones, in which Fred took ballet lessons to improve his bowling skills, and then find that he can only bowl perfectly to ballet music.
 * In an episode of The Simpsons, Homer becomes an opera singer when an aficionado hears him singing while in the bathtub. It turns out that he can only sing well while he's lying down, so all his performances have him on a psychiatrist's couch.

Real Life

 * Have you ever tried to remember song lyrics with the melody removed? Or tried to recall song lyrics without humming the tune to yourself/singing it? Some people can't even recall the order of the alphabet without the song.
 * Or had to mime entering in a telephone number on an invisible phone in order to recall a number?
 * How about moving your fingers when trying to recall a web address?
 * The above two are actually examples of procedural memory, or, colloquially, "muscle memory." It's what happens when you perform a specific action the same way so many times that the brain eventually just gives that particular action its own subroutine, so you don't have to consciously think about doing it anymore.
 * Have you ever tried to remember why you went to a particular room by going back to a room where you knew?
 * Often justified or subverted in that the objects or situation that made you go to the other room in the first place may still be there.
 * Or tried to play quarters without drinking?
 * Often invoked as "study aids" for students. This is why, among other things, you're supposed to be sitting at a desk as you study the material -- so you can remember the material when you're sitting at a desk for the test.
 * Many teachers also recommend studying in conditions that will exist during the exam. Set a time limit equal to how long you'll have on the exam. Use the exact same pencil. Depending on if the school allows it, you can even go to the classroom and sit in the seat you'll take the exam in and study there.
 * On a related note, you're supposed to only use your bed for sleeping because if you try studying in bed, you'll find yourself getting sleepy because you've strongly conditioned yourself to associate your bed with sleep.
 * This works both ways. Some people have problems with insomnia because they've stopped being conditioned to associate their bed/bedroom with sleep. The remedy for this is to move things like computers, TVS, and exercise equipment out of the bedroom and to minimize non-sleeping time spent there.
 * This is also why is not a good idea to stoke yourself up on coffee or energy drinks to cram in your revision, as you won't remember it until you're stoked up on coffee or energy drinks -- probably not a good idea when you're about to go into an exam.
 * Studies have shown that smells are also quite good at evoking memories. So study while wearing a highly unique perfume and then wear it again the day of the test. Legend has it the ancient Greeks were fond of rosemary.
 * Averted with performance under extreme stress. It used to be approached under two theories: learn the action normally and then apply stress versus learn action under stress. Extensive research has proven beyond a shadow of a doubt that the former is a far better way. In the book Extreme Fear, the author goes into the psychology, but essentially your brain shuts down too much in panic mode and focuses only on what it knows will work for it to learn successfully while under duress. So learn calmly, and then introduce distractions.
 * There are people who become used to listening to a certain noise at night find it harder to get to sleep if it stops.