Associative array not cleared when function is done

In reply to wyc123:

That is because your function has a static lifetime, and all the variables declared inside the function (as well its arguments and return value) have a implicitly static lifetime as well.

You need to declare the function with an automatic lifetime (preferred), or the individual variables you want. See The life of a SystemVerilog Variable.