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

Re: Do we have to free a FILE pointer? 80 80

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

Re: Do we have to free a FILE pointer? 80 80

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.