Visual SLAM
Visual SLAM, as in ORB-SLAM, runs three jobs at once. Tracking estimates the camera pose in every frame from the features it sees. Local mapping adds keyframes and new map points. Loop closing watches for places seen before, and when it finds one, it corrects the drift that built up along the way.
Three threads
Tracking matches features in the new image to map points and solves for the camera pose. Local mapping decides when a frame is new enough to become a keyframe, then triangulates new map points and runs a small bundle adjustment. Loop closing compares each keyframe to old ones using place recognition. When it finds a match, it adds a constraint between the two keyframes and optimizes the whole pose graph:
What to notice
As the robot drives, small tracking errors add up, so the red path and the map points it builds slowly drift from the truth. When the robot returns to the start and recognizes it, the loop closes and the error is spread back along the whole path. Without loop closure, the drift just keeps growing. This is why mapping a building usually means driving loops.