This is in regards to a situation where Session is used to store some temporary data – one example being information entered during a multi-step registration process.
If a website has a number of such sections – which wants to utilize the session as temporary data store for pages within the section, what is a good way of cleaning up the session when the data is no longer required, considering that the user may simply navigate away from the section so the pages themselves cannot be used for cleaning up.
[Edit] In my case, the prime drive for this is to reduce network traffic as session is stored out of proc, but same concern can apply for memory bound applications and performance in general. Also unexpected data in Session can easily lead to difficult to track bugs.
Time should keep the session clean. Sessions should expire and in doing so nuke all their data. This is default behaviour.
I’ll agree that storing too much data in a session is not a great thing for server-resources but as you know, it’s sometimes a necessary evil. If you’re really that bothered, consider moving your sessions off to SQL Server. It’ll add a smidge of latency but you’ll be able to handle far more users.