It’s deliberate - if you don’t access the flash, then you clearly haven’t rendered the message, so it should stay until a request that does.
Otherwise any random request (say an AJAX autocompleter) that happens to come in before the next page request (which is the one we intend to show the flash message) will steal the flash value and throw it away.
There was another problem with clearing the flash hash on every request. There was a period when rails did do this, and it caused a massive security problem for one of my projects: hitting the flash meant accessing the session variable, and since the ability to explicitly turn off the session in certain controllers was removed a long time ago, this meant that all requests accessed the session variable. Which meant they all wrote the session variable, because Rails writes the session cookie back out if the session was loaded. Which meant if you had a request that said the response was cacheable, all the users hitting that action got the cached session cookie of some other user…
More generally, it’s not intended that all controller actions will load and set the session, even if they don’t use it. It’s supposed to be lazy-loaded as you say, and that means the flash is too.
I don’t understand why you are putting stuff into the flash hash if you don’t actually want to render it again though? It’s specifically there to put stuff into the session to be renderd by the next layout request.
Just use an ordinary ivar if you don’t want that.