I curious what you try to achieve here, let me explain default behavior and explore some possible extensions with you.
Mendix will automatically clean up Sessions (i.e. server-side logout) on inactivity. When a user “hasn't been seen” for 10 minutes, its Session will be cleaned up. To prevent unwanted logouts, a keepalive call is executed every 5 minutes by the browser when no microflows/data retrieves takes place.
Conclusion: users are already logged out automatically within 10 minutes after they close the tab.
If you want to make it safer, for example: a quicker automatic logout, you could tweak the duration of the Session or disable the keep alive. This is described here.
If you want to do extra stuff, for example clean-up other records I would suggest to associate them to the Session and setup a delete behavior like this:
If you really want to do something on close page, you could build a widget to subscribe on the OnBeforeUnLoad function of the window, but you are never sure this is actually triggered.