memory leak

what precautions needed to avoid memory leak?How os or compiler deals with it.
and please explain about void pointer!
thanks!

I think you are confusing between Null pointer with Void Pointer. Null Pointer is a special reserved value of a pointer. When a pointer has that null value it is pointing nowhere. Whereas, Void Pointer is a type of pointer that points to some data location in storage, which doesn’t have any specific type. Most common example is when you dynamically allocate memory in heap in your program using malloc or calloc or new (in C/C++) they return a void pointer pointing to the first memory location of allocated memory.

As for precautions, always make sure you free the memory using free or delete (in C/C++). Look at this sample C program which is provided in the wiki page. Also, you can read more here.

EDIT : Watch this video on memory leaks. Hope this helps.

1 Like