Add a reference count to tables, only free if the table is not in use.