meaning of free() in C.
Posted on 2003-11-10
I have a code like below ..
if(xmlString != NULL)
xmlString = NULL;
xmlString = (char *) malloc (maxSize);
if(xmlString == NULL)
cout << "Insufficient memory available to allocate to xmlString" << endl;
My reqrmnt was to dynamically allocate memory for xmlString each time I call the function . But while i am debugging using dbx ,I found that even after the execution of statement free(xmlString) if I print xmlString in dbx it will show me the contents of the string .
My qtn is what exactly free() will do ?
Will it delete the content and release the memory to OS ?
OR Does this mean xmlString is not valid after execution of free(xmlString) ?
If I free(xmlString) and again alloacte memory using malloc will this alocates in same meory space ? or diff memeory space ? will there be any prob by freeing the memory and allocating diff amount of memory again in a prog ?
Thanks for ur precious suggestions .