Destroy modalBar after last occurence is replaced

This is for issue #3748.