House elves can only be let free if their owners give them clothing. Dobby's favorite piece of apparel is the sock, which he obtained after Harry tricked Lucius Malfoy by throwing one to him, which explains the rising number of them at his display on the tour. There are two possible explanations as to why Dobby was given a sock: either as a joke or because Harry threw it to him. If it was a joke, then it was probably done to humiliate Malfoy; if not, then perhaps Dumbledore wanted him to know that they were friends. Either way, it shows that not all house elves are treated well. House elves serve their masters loyally until they are no longer useful. Then they will go to any length to avoid being killed. This is shown by Dobby trying to save Harry from death when he was about to be thrown into Azkaban. He knew that if Voldemort found out that Harry was alive, then he would need to protect him at all costs. Therefore, he tried to escape so that he could fight against Voldemort with Harry's help. House elves are very loyal to their owners and will do anything for them. This is shown by Dobby risking his life for Harry when he was being attacked by Voldemort's dog, Crookshanks.