Freeing memory after allocating memory?

Hello!

Hey all!
I've just recently learned how to use classes. To learn how to use 'classes' I've created a program that reads numbers from a file and stores them into 2 arrays. I dynamically allocated an array and have been using the same .txt file to test my work. After just now trying to use another txt file... It was reading in the same amount of lines as the previous file had. No matter how many lines I add or delete.... it keeps telling me that there are 4 lines of data that was read in. Any idea why this is happening?
Maybe your code is buggy in the first place?
Post it for us.

This shouldn't be a result of not freeing memory. (though if you're not freeing it, you should, otherwise you could eventually get at 100% ram usage)
I found the issue. It wasn't buggy. It was me. The first line stated how many lines where to be used.

I would like to know when it would be appropriate to delete allocated memory.
I usually delete allocated memory if there's a greater than 50:50 probability that I won't need it again, but that's me. I'd expect that some people keep it to the end if they know there's a good chance they [edit] will not [/edit] need it again and others delete it as soon as it's not needed even if they will need it a second later.

-Albatross
Last edited on
I get rid of it when an object is deleted, or the end of my program. As long as it's deleted, it shouldn't really matter.
Topic archived. No new replies allowed.