Re: ? free()
- Posted by Greg Haberek <ghaberek at gmail.com> Apr 20, 2005
- 428 views
> You can't. > > That is why the interpeter when it sees a FREE() function > must determine what variable originally allocated the memory > and set that variable to zero. > Then if you try to use that variable, or any copies of it, > the use will cause an error instead of probigate the error > throught the program. This is extremely frustrating for me, since I don't understand how you'd ever let yourself get into such situations. The Interpreter shouldn't have to babysit your variables for you. You, the programmer, should know what variables are memory addresses and, when freed, stop using them. When you have an atom that contains a memory address, all that atom really contains is a number. The Interpreter doesn't know that number is a memory address. You know its a memory address because you assigned it that. Why should the Interpreter be responsible for your memory addresses? Shouldn't you, the programmer - attempting to make good programming practices - be resonsible for knowing what variables hold a memory address and ignore or zero them when that memory address is no longer valid? I've been using Windows API routines that require frequent allocations and frees of memory addresses, and I have never, ever run into an issue where I continued to use a memory address after I'd freed it. Any good programmer wouldn't let himself get into a situation like that. Just my $0.02, ~Greg