Use momoization in sdb_ns_free and sdb_ns_sync to avoid infinite recursion