there is no real good way for it. As you cannot make sure that a user is logged in. You can keep track of the time for a session to expire, and -say it is 5 minutes of inactivity- run a CRON job every few minutes to verify for active sessions (This requires you to keep track of the active sessions in a table: Sessionid & last page load). Sessions that are not active anymore need to release their items (Obviously: You would need to create a session handler that stores session information for you).
Alternatively: Do not remove items from the main database...