This is how Ryan fight Marluxia and get their Memories back in Ryan's Quest: Chain of Memories.
[They found Marluxia, the Dazzlings and Megaminé]
Marluxia: You've defeated, Axel. (Laugh) The Keyblade's Power--- how I've longed to make it my own.
Ryan: Let the Dazzlings and Megaminé go!
Marluxia: You've no chance of winning. [to Megaminé] Megaminé... Erase Ryan's Memory.
Adagio: If she do that, then...
Marluxia: That's right. Ryan's heart will be destroyed.
Sci-Ryan: His heart, destroyed?
Evil Ryan: Oh no!
Crash Bandicoot: You can do that?
Marluxia: I'd rather have preferred him unmarred, but he can be rebuilt--- more to my liking with time, Megaminé, do it.
Megaminé: No. Ryan forgave me even when I deceived him. So how could I destroy his heart? There's no way! I don't care what happens to me. I won't hurt Ryan! I won't do it!
Marluxia: Then you will---
Ryan: Do it, Megaminé!
Ryan: I don't care! You can erase my memory!
Sonata: Ryan, why'd you say that?!
Ryan: Because, who will I look after if I don't have Megaminé? So just do it! Erase my memories. Destroy my heart. I promised! I'll always protect you! You have to believe me!
Ryan: I don't need any memories to take on someone like Marluxia!
Sci-Ryan: You bet! Even if Ryan forgets it all, We won't forget!
Crash: Sci-Ryan's right. We can remember everything for Ryan!
Ryan: See, I'll have all my friends' memories, so I can piece my own together again!
Marluxia: You ignorant fool. If Megaminé uses her powers to erase your memory, you'll be nothing but an empty shell. Your heart will no longer be able to feel or to care. Just like---Vexen's pathetic imitation of your Brother.
Cody: (Voice) Take another guess.
[He appeared out of the portal and attack Marluxia]
Marluxia: It can't be!
Replica Cody: Sorry, Just an Imitation.
Crash: Um, where's the clone of the Dazzlings.
Cody: They're gone. They left the Castle before I recovered.
Marluxia: You're a shell---a shell who has had everything taken! Everything!
Cody Replica: What can you possibly think I ever had? Both my body and my heart are fake. But...there is one memory I'll keep...even if it's just a lie! Whether it was a phantom promise or not... I will protect Megaminé!
(A flower petal falls from the air, turning into Marluxia's scythe in his hand)
Marluxia: You would knowingly shackle your heart with a chain of memories born of lies?
(Ryan readies his Keyblade)
Marluxia: You would be one who has a heart, yet cast aside your heart's freedom?
(The Cody Replica puts his arm in front of Megaminé)
Marluxia: You turn from the truth because your heart is weak--- You will never defeat me!
They are fighting him and they defeated him
Sci-Ryan: Is he gone?
Ryan: Yes. I think he's gone.
Marluxia: You could say that.
[They are surprised. Marluxia reappears)
Marluxia: However, what you destroyed was merely an illusion of me.
(Ryan gets angry)
Cody Replica: So what!
(Cody strikes Marluxia, but it turns out to be another illusion)
Cody Replica: Another imitation.
(They look to the door up ahead)
Ryan: He's really...in there?
Ryan: I knew it. I can feel his power. It's trying to destroy my heart.
Crash: Whoa, we'll just take care of him together!
Matau: Ryan! C'mon!
Ryan: Brother... Protect Megaminé.
Cody Replica: You don't...mind?
Ryan: (Smiling) Should I?
Cody Replica: All right.
Sci-Ryan: Oh boy, Ryan! This is the final battle!
Crash: Are you ready?
Ryan: It's our last battle!
(Ryan enters through the doorway and finds Marluxia hovering in the air)
Marluxia: Soon the emptiness will shatter your heart and snuff your spark---here in this world of nothingness!
(He waves his arm, and a tornado made of wind and flower petals surrounds him. Ryan is pushed back from the pressure. He gasps as he sees Marluxia on top of a giant mechanical creature)
Marluxia: As lightless oblivion devours you---drown in the ever-blooming darkness!
(Ryan defeats Marluxia and the machine)
Marluxia: Your hopes are doomed to the darkness!
(Marluxia transports Ryan to another location; a blue void with white chains in the distance. Marluxia and Ryan are on top of a large floating vehicle, and a giant angel holding a scythe is behind Marluxia. Ryan defeats Marluxia one last time. Marluxia screams in agony as he, the vehicle, and the angel disappear. Marluxia reaches for Ryan, but fades away into darkness and flower petals. Ryan leaves the battleground and reenters the castle. They close the doors and Ryan locks the doorway with his Keyblade)
Ryan: You okay, Cody?
Cody Replica: Not Cody. I'm a fake. I can't remember why I was created or where or when... All that's inside of me---is time with you and Megaminé. But I know those memories are not real.
Crash: So, Megaminé, can't you use your magic to put Cody's memory back to normal?
Megaminé: Well, I---
Cody Replica: It's all right. I'll deal.
(He begins to walk away)
Ryan: Wait! Who cares if someone created you? You are you and nobody else. You have your own heart inside you. Those feelings and memories are yours and yours alone. They're special!
Cody Replica: Ryan, you're a good guy. I don't have to be real to see how real your feelings are. That's good enough!
Ryan: Cody! Cody....
Adagio: Well, it's time for me and the girls to leave.
Ryan: What, why?
Sonata: Because we have to go home.
Aria: Look, Ryan, I know you want us to change our minds, but it's time for us to move on, now.
Sonata: You have you friends who can take care of you. And you don't need us anymore. And now you're finally stronger then us. And Ryan, hope you can see us again. Bye.
Ryan: Adagio? Aria. Sonata. I guess you could see me when I get my memories back. I vow, I will see you three again. When I return.
Evil Ryan: Ryan? Did you make a vow?
Ryan: Yeah. Once I get all my memories back, I'll find them someday.
Sci-Ryan: (To Megaminé) Can you put our memories back?
Megaminé: Yes. Not remembering something doesn't really mean that it's gone.
Crash: What d'ya mean?
Megaminé: When you remember one thing, that leads to remembering another---and then another and then another. Our memories are connected. Many pieces are linked together like they're in a chain---that makes up each of us. I don't actually erase any memories---just take apart the links and rearrange them. You still have all your memories.
Spikewave: So you can put 'em back together?
Megaminé: Yes, but first, I have to undo the chains of the memories I made on my own. After I've done that, I have to gather up the memories scattered across each of your hearts and then reconnect them. It might take some time. But I think it might work. No---it will work. I'm sure. It's my turn to look after you.
Ryan: All right. We all really trust you.
Spikewave: What now? (Gasp) Wait a minute! You said you have to undo the links of the memories you made. But that means...
Megaminé: Yes. You won't be able to remember anything about what happen here.
Ryan: Not even you?
Megaminé: I'm sorry, it the only way, I'm afraid. Ryan, you have a choice. You can lose your memories about this castle and reclaim your old ones... or keep your memories here and give up the memories that you've lose.
Ryan: Do I have to... chose?
Ryan knows he lose his memories about the Castle and Megaminé, but he need to get his memories back. So he made he's choice.
Ryan: I want you to make me like I was before I come here.
Megaminé: Oh, okay. Nobody needs to keep a bunch of memories that aren't real, right. You want to remember all of the people who are really important to you. Anybody would choose that.
Bertram: To remember again, we have to sleep in that?
Megaminé: Yes. It's going to take a little time, but I'll take care of you.
Matau: Wait, when we wake up, we won't remember who you are anymore...
Sci-Ryan: But how are we gonna thank you?
Spikewave: Don't worry about that! I'll just make a big note in my journal. And it will say, "Thank Megaminé."
Sci-Ryan: Oh, good. That makes me feel better.
Crash: Well, good night, then, Megaminé.
Megaminé: Good night, Crash.
Megainé: You too, Ryan.
(He starts to climb into the pod)
Megaminé: All of this may have started with a lie...but I really am glad that I can meet you, Ryan.
Ryan: Yeah, me too. When I finally found you, and even when I remembered your name, I was happy. The way I felt then--- That was no lie.
Ryan: No, not goodbye! When I wake up, I'll find you. And then there will be no lies. We're gonna be friends for real. Promise me, Megaminé.
Megaminé: You're going to forget making that promise.
Ryan: If the chain of memories comes apart, the links will still be there, right? So the memory of our promise will always be inside me somewhere. I'm sure of it.
Megaminé: Yeah, you're right. Okay, it's a promise.
Ryan: Good. Until later.
(They join their pinky fingers together to signify their promise. Ryan waves goodbye and jumps into the pod)
Megaminé: A promise... Huh... Ryan, some of your memories' links are deep in the shadows of your heart and I won't be able to find them. But don't worry--- You made another promise to someone who you could never replace. She is your light. The light within the darkness. Remember her, and all the memories lost in the shadows of your heart will come into the light.
Ryan: Another promise...
Megaminé: Look at the good luck charm. I changed its shape when I changed your memory--- But when you thought of her just once, it went back to the way it was.
(Ryan takes out Meg's charm and looks at it. The pod closes, and Ryan is surrounded by darkness. He stares at the charm, trying to remember his friend. Megaminé appears beside him. Ryan remembers his friends from Traverse Town and Canterlot High. He shakes his head as he continues to try to remember. Cody's image appears in his mind, and then, finally, Meg's)
(The darkness becomes light)
Ryan: My friends...
(Megaminé starts to float away)
Megaminé: Don't worry. You might forget about me...but with our promise, I can come back.
Ryan: A promise is a promise.
Megaminé: Yes. One day the light---it will be ours, and it will bring us together. Til then---I'll be in your heart.
Ryan: Right. Forgotten---but not lost.