00:00:00,367 --> 00:00:02,950 SPEAKER: Now that we've created our dictionary data structure, it's time to free up all of that memory that we had previously allocated. So how does one free a linked list? It might look something like this. Here I follow the same convention that I've used throughout the walk through where the node pointer, called head, refers to the very first node in a linked list. The code to free a linked list might look something like this. Here I assign a new node pointer, called cursor, to head. Remember that following the convention of this walk through, I've used head to refer to the node pointer that points to the very first element in a linked list. For your hashtable, it might be named something different. Then I enter a loop that advances as long as the cursor is not null. Within that, I create a temporary node pointer, initially pointing to cursor. I advance the cursor and then free that temporary node pointer. What does that look like? Well I leave it to you to follow through this example, erasing and creating arrows as necessary to see how this method of freeing will ensure that no node is left un-freed. If instead of a hashtable or linked list, you've decided to implement your dictionary as a try, then you'll unload from the bottom to the top. What I mean by this is that you can travel to the lowest possible node, from there you can free all of those pointers and children because you know they're not linking to anything else. From there, you can then go up to the parent node and backtrack upwards that way, freeing all of the elements in each children array until you hit the root node. If you get stuck, remember to take pen to paper and draw out your try data structure in whichever schematic makes most sense to you. And there, you can ensure that following your code, you free all of the nodes that you've ever created. If you've chosen to go with a try for a data structure, then I challenge you to look at recursion for an elegant implementation of the unload function. Finally, whether or not you've chosen a hashtable or a try, make sure to run valgrind, which will check to make sure that all of the memory that you've allocated in your program, you've also freed by the end. If valgrind gives you the OK, then you're good to go and you've successfully unloaded your dictionary. My last couple tips to you before you go out and code, is to try make it easier on yourself to debug. Pass in a smaller dictionary to speller instead. By default, speller will run with the large dictionary file. But also, try passing in the small dictionary file provided in the distribution code. Or you can even make your own dictionary and your own input text file. Perhaps, use the words that we talked about today, fox, food, dog, and do. Finally, pen and paper are going to be your best friend. Try drawing out your dictionary as you create it, load it, check it, and finally, unload. My name is Zamyla, and this was speller.