In the first case tf2_ros::StaticTransformBroadcaster staticBroadcaster2 go out of scope , all the callback will be stopped being callded, which is not the case for second one.