A device for and a method of milking animals. Said device is provided with a cleaning device for cleaning at least a part of a milking machine, the cleaning device comprising a cleaning start device for starting the cleaning. A milking machine is provided with a computer comprising a memory. The computer is adapted to store the points of time of the visits of the animals to the milking machine in the memory. The cleaning start device is activated by a cleaning start signal issued by the computer on the basis of historical data in relation to the points of time of the visits of the animals stored in the memory.