In ep31, Light says he had misa sign off as the notes owner, and hence she loses her memory. In the earlier eps, it was shown that Light used misa's note to keep his memories. But as soon as the book was given away, why didn't he lose his memories?
This is actually quite a math, but very simple:
Before ep27 there was 3 Death Notes in the human world - one of the police (original Light/Ryuk's Death Note) (it's actually the investigation unit but I will write police for convenience), second of Light (was original of Rem), and third was misa (original brought to her by Rem).
By the events of ep29 the police Death Note had been traded to Mello's mafia.
In ep30, Light took Misa's Death Note in his care so he won't forget, and sent his currently Death Note to the police, so his father would use it to get the Shinigami eyes from Ryuk. ~ Currently in this phase, Misa is own the Death Note Light holds, so while he gave up his Death Note, Misa is the owner and Light is the borrower so he won't forget; In other words: Death Note #1 - Mellow, Death Note #2 - The police, Death Note #3 - Misa.
By the end of ep30, the police took back Mello's Death Note - the third DN brought back to it's original Shinigami. The Police Death Note that Shuiciru - Light's father holds and its owner, is dead, while Light holds the Death Note of the police, meaning he's now the new owner of this Death Note, while this DN is held by the Police for the rest of the series. Light doesn't need Misa's DN for his memories and gives it back to her.
In the Near arc, he made Misa forfeit her DN and give it to Mikami, becoming normal girl without DN memories. Light memories got nothing to do with it since he owns the police DN.
All this also explains the reason why Mikami couldn't see Light's Lifespan in the latest episodes - he was the owner of the Police DN, and didn't need to actually hold it to regain his memories.
For the same reason he was able to defeate Yotsuba Kira: When he touches a note that he once owned, he temporarely regains/ keeps his memories.
I don't find a reference just now but some time after the first major climax half way through the manga, Light explains to Ryuk/ us that he keeps physical contact to a note using a corset. As long as he touches a note he once owned (and at some point he owned every last one that became part of the human world at some point), he temporarely holds his memories. And since it is old trickster Light, temporarely happens to be several months.
I will go through the manga again late this week and hope I can find the chepter.