954,505 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Do we have to free a FILE pointer?

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

mohammadalipak
Newbie Poster
19 posts since Jul 2007
Reputation Points: 10
Solved Threads: 0
 

>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.

Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
 

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.

TkTkorrovi
Junior Poster
170 posts since Mar 2005
Reputation Points: 85
Solved Threads: 13
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You