After the ring is destroyed Frodo begins to remember all of the things Sam did for him while Frodo was sick from the ring and Sauron. He sees his loyalty, his love, his trust even when Frodo gave him no reason for these things. He sees Sam literally carrying him until the end, all of the times he told Frodo not to leave him.
When he talks about what he's remembering from the Shire he's remembering those things with Sam in them, all of the moments they've shared at home.
And then Sam talks about Rosie Cotton.
(THIS IS THE FACE HE MAKES AAAA)
It's in that moment that Frodo knows he will eventually have to leave, because he thinks Sam will never love him.
It isn't that at all. It is just that Sam has never entertained the idea that he was good enough for Frodo, especially now that he is a hero.
Frodo allows himself a moment of selfishness, a moment to be close. Because if these are his last moments he wants to express his love ("I'm glad to be with you, Sam Gamgee, here at the end of all things") while he can.
But it isn't their last moment.
When they look at each other in the House of Healing it is the same look--
"I love you, whether or no."
(OH DID YOU SEE WHAT I DID THERE WITH A TWO TOWERS BOOK QUOTE.)
It's why this is what Frodo looks like at Sam's wedding when he isn't looking anymore.
It's why the last thing he does before leaving Middle Earth is kiss Sam.
He says "My dear Sam, you cannot always be torn in two."
And so Sam goes, and he loves Rosie whole-heartedly.
But he isn't truly one until he sails to Frodo again, so many years later. That waiting period isn't so bad, though; they've waited a lifetime for each other, so they can wait a little longer.