If the application is going to shut down, it has to take care of removing the tray icon. A well written application should do that. Let's hope for the best.
However, I sometimes have indeed dead tray icons lying around that vanish when you touch them. Looks like a rather common problem
Also, have a look at
this post on StackOverflow. It really looks like you can either hope that the application cleans up after itself (if you just let it) or just accept your fate.