After using FILE *pFile for file I/O (all the way from fopen(pFile, ...) to fclose(pFile) ), my pFile pointer still points to 0x7803a710 . So I figured I better free it.
However, when I try free(pFile) , it pauses execution (while debugging - though no breakpoint is set). When I hit F5 again (continue execution) & check the value of pFile , it is still 0x7803a710 . I was expecting it to be freed to 0x00000000 .
Does anyone know how to free a FILE pointer? Thanks

11 Years
Discussion Span
Last Post by TkTkorrovi

>it is still 0x7803a710. I was expecting it to be freed to 0x00000000.

Your expectation is not realistic. Freeing some memory do not mean
that is zero out. It means that is available for other uses.
A perfect example would be if you declare an int variable and do not
initializes it, what do you get? We say "garbage", but in reality is whatever that piece of memory holded last from previous use.


fclose is all you need to free a file pointer. About your pFile pointing still to the same place... pFile is just a variable, and no function can change its value, unless you give it as &pFile as argument, in which case that function should expect pointer to pointer as argument. Freeing memory affects the memory block allocated, but doesn't change the pointer which you used to point to the allocated memory.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.