I suddenly see what you did wrong: you must not close the </i>def</i> function with <b>{/def}</b>.
To destroy the variable you've created, you can use <i>undef</i> (see http://ez.no/doc/ez_publish/technical_manual/3_6/reference/template_functions/variables/undef).