Explain the following:
a) Memory Leak
b) Dangling Pointer
a) A Memory leak occurs when memory is allocated and then never released. If the code’s active lifespan is very short, it’s usually not a huge issue. However, if the code is expected to keep running, a memory leak can eventually cause the system’s memory to be entirely clogged with memory that has been allocated but is no longer actively in use.
b) A dangling pointer is a pointer that was used to point at a dynamically-allocated block of memory which has subsequently been de-allocated, but the pointer remains. If that pointer is then referenced, the memory might still contain what it used to contain, or it might have been re-allocated to something else.
Comments
Leave a comment