The whole point of weak refs is so that you don't need to clean up things like this. you should just use weak ref and let GC do the job. Listener will be alive as long as sandbox is.