freeing the memory allocated by calloc 
Author Message
 freeing the memory allocated by calloc

Hi all,
 can anyone say me what will happen if i dont free the memory
space
 that is allocated using the calloc() function. my doubt is that,
 after the program execution itself is over, the pointers that are
 created in the file will also be destroyed, then the memory that
 is allocated to that pointed using the calloc() should also be
 freed right?? is this what is happening really?? if not what if
 the pointer is not freed, and what are its effects after the
 program execution is over??? will it affect the execution of
other
 programs??
 thanks in advance for the answers

 cheers
 thiyagu



Sun, 09 Jan 2005 17:30:53 GMT  
 freeing the memory allocated by calloc

Quote:

>  can anyone say me what will happen if i dont free the memory space
>  that is allocated using the calloc() function.

No, because this depends on the implementation, and in fact on the OS.

Quote:
> my doubt is that,
>  after the program execution itself is over, the pointers that are
>  created in the file will also be destroyed, then the memory that
>  is allocated to that pointed using the calloc() should also be
>  freed right??

Usually, yes. It would be a poor OS indeed that did not deallocate all
memory allocated by a terminating program. However, there are some poor
OSes indeed out there, and I wouldn't be surprised if there were one
that didn't do this.
In any case, what happens after your program is terminated is beyond the
control of the C Standard, and does depend on the OS you use.

Note, though, that there are other, very good, reasons to free()
everything you *alloc(). Debugging is one. Discipline is another. And
one day, you may need to turn your program into a library and
incorporate it into another program, and what then, if your program, now
library, leaks memory?

Richard



Sun, 09 Jan 2005 18:44:11 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. doubt - freeing the memory allocated by calloc

2. allocating memory via malloc/calloc

3. What is the proper way to allocate and free memory in this instance

4. freeing allocated memory from included files

5. newbie malloc problem: free memory allocated to structures

6. problem allocating/freeing memory of multidimensional arrays

7. Non-allocated memory- is it freed?

8. freeing allocated memory...

9. Freeing allocated memory

10. freeing allocated memory...

11. Freeing memory allocated inside a function

12. Freeing allocated memory by the server

 

 
Powered by phpBB® Forum Software