When you log out, your cookie session is deleted - this means that your internet browser no longer remembers how many grains you earned during that session. However, you do not loose your overall total. This is stored permanently in your profile and all rice raised is stored permanently in the Freerice grand total.
Why would we do that? Freerice is used by many schools as an education tool. This means that students play Freerice on shared computers in their classrooms. When the lesson is over, they need to log out and allow for a new set of students to use the computers. If the browser session is not cleared, the new set of students would start playing with the same number of grains earned by the previous set of students.
However, if you are not on a shared computer, you can remain logged in and the grains raised during that session will be stored for 30 days. The total number of grains raised is stored in your profile view permanently.