Energy dissipation accompanying atomic-scale friction: Nonlocality and memory