I don't understand this statement and code below looks quite dangerous for me, because you  left in YExternalWidgets::_externalWidgets already deleted pointers, so another destructor ends up in seg fault. I expect that after such destructor if pointers should be deleted, then also map must be empty.