A locking device is adapted for a first object and a second object that are movable with respect to each other. The locking device includes a first element and a second element. The first element can be in a locking state or an unlocking state. The second element drives the first element and thereby moves the first element from the locking state to the unlocking state in response to the second object being displaced with respect to the first object from a retracted position to a predetermined position in an opening direction.