You can check that on dialog close or edit or any other event (
/help on dialog) if the %variable exists but without any value to /unset it.
e.g:
ON *:DIALOG:*:*: {
if ($devent == close) {
if (!%variable) && (%variable !== $null) { unset %variable }
}
}