If you have trouble remembering the difference between a leak and a dangling pointer, this may help. Before either problems occurs, memory is created on the heap and the address of this memory block is assigned to a pointer. A leak occurs when the pointer gets deleted, leaving a block with no reference. In contrast, a dangling pointer occurs when the memory block is deallocated, leaving a pointer that points to deallocated memory. Both are shown in the following figure.