Passing variable values back to parent context

Thank you, I have managed to solve the problem with a shared variable. In this thread, Is there a way to unset SHARED variables?, it is written, that shared variables consume too much memory. How can I prevent this?