Why do you think updating a table takes "a lot of memory"? or why do you think its "heavy work load to server"? Its basically nothing. There is no solution other than using a database as you described, because browsers don't implement any kind of messages for when a user leaves your site. You've got to track this yourself by updating a table with last access time and so on.
And even if browsers did implement "user has left your site" type messages, you would still have to update a database and read from one to track this stuff.
Plus, even if browsers sent these kinds of message, if the user lost power, the browser would obviously not be able to send it.