Purging session data on devel user switch
Problem is - $_SESSION was never really meant as temporary data storage. Proper and safe way is to use cache_set() to store data.

First argument, $cid is customary used as a string with sections separated with :, so in your case it should look about like that:

global $user;
// ...
cache_set('mymodule:' . $user-&gt;uid . ':' . $user-&gt;sid . ':kind_of_data',
          $data, 'cache', CACHE_TEMPORARY);
// ...
$data = cache_get('mymodule:' . $user-&gt;uid . ':' . $user-&gt;sid . ':kind_of_data',
                  'cache');


That way you will allow Drupal to benefit from database permanency, memcached speed, whatever you please. And by including uid of current user, you are sure data is well separated and no collisions will occur. Including session ID allows proper anonymous user handling. For logged in part $user-&gt;sid might be safe to ignore, depends if you want data to be shared between logged in seats or not.

If you use session id as a part of cache key, like above, entries will be only valid for one session. If your site has few users, obsolete cache entries are not a problem. And if you have many, you should store both sessions and cache in memcached, apc or similar technology anyway. Database is simply to slow for this. Memory based cache engines are very good at automatically destroying unused entries when needed, destroying them from code is a waste of time and effort.