Again, stuff that you don't learn in school, but thanks to the power of the Internet your answers become solved. I'm charged with making a class that reads in a file, parses strings from the file and allocates memory on the heap for those strings. I must use cstrings, new, and delete. Here's the gist of the program:
- Main creates a class variable "Dictionary."
- The constructor for the Dictionary class:
- Reads an input file
- Creates an array of "Entries" on the heap
("Entry" is another class consisting of pointers to two dynamically allocated strings)
- A menu is presented
- etc.. etc..
So what did I find out that was so novel? Thanks to
this post on
stackoverflow, (yes... that's my post), I realized that I had a memory leak with my Entry Class. I was storing the pointer to the dynamic memory in the entry, but not deleting it when I was done.
A new commandment: That which owns the pointer to the heap gets to delete[]