rishabh agrawal


{ City } bangalore
< Country > india
* Profession * tech. lead
User No # 30067
Total Questions Posted # 0
Total Answers Posted # 1

Total Answers Posted for My Questions # 0
Total Views for My Questions # 0

Users Marked my Answers as Correct # 106
Users Marked my Answers as Wrong # 22
Questions / { rishabh agrawal }
Questions Answers Category Views Company eMail




Answers / { rishabh agrawal }

Question { 41662 }

What is dangling pointers?and what is memory leak?


Answer

A1 - Dangling pointer points to a memory location which is
being removed.
E.g.
int* a = new int;
int *b = a;
delete b;

Now a will be a dandling pointer.

A2 - Memory leaks occur when memory allocated to a pointer
is not deleted and the pointer goes out of scope. This
allocated memory never gets de-allocated and remains in the
heap until the system is restarted.
E.g.
void foo()
{
int* ptr = new int;
*ptr = 10;
...
...
}
Since ptr is allocated memory using 'new', but no 'delete'
is called, hence memory allocated to ptr will leak.

Is This Answer Correct ?    106 Yes 22 No