Do I have to removeMouseListener before I delete component?


#1

I am wondering if there is any negative side effects if I delete child components without removing the mouse listeners from the parent component first?


#2

No, you don’t have to do it unless you’ve done something special with it before.


#3

What do you mean by “something special”???


#4

If you are 100% sure, that you are not inside a mouse event and that none of them occurs during your deletion, then you probably don’t.

  1. You should do it, if this deletion happens outside the MessageThread, because in that case a mouse callback could fire at any time. In doubt a MessageManagerLock could help, I think
  2. If the removal is scheduled inside a callback from that Component, that you are currently removing, you are obviously cutting the branch you are sitting on

This list might be incomplete…