 Hermione finally learned that elves needed a bond. Dobby wanted to be a free elf because he was mistreated by Lucius Malfoy. But even he needed a magical bond. Draco laughed hysterically when he figured out what Dobby had done all those years ago. He bonded with Harry and the latter had no idea. 