Pointer Memory allocation

This tip submitted by Krishnamoorthi on 2005-12-18 01:38:56. It has been viewed 17616 times.
Rating of 5.9 with 148 votes



When ever you deallocate the memory reset the pointer to NULL to make sure that you do not use a dangling pointer. For example:

free(Session);
Session=NULL;

Now if you try to use Session, then it will crash your program immediately, rather than using invalid memory, which will cause very hard-to-find problems.



More tips

Help your fellow programmers! Add a tip!