Part of the actors' training is to improve their ability to memorize things. Practice improves their memory so, with time, it becomes easier to memorize lines. But actors rarely memorize the entire script before the filming starts.