clean a resource properly when exiting a plugin