Memory Leak question

This is a discussion on Memory Leak question within the C++ Programming forums, part of the General Programming Boards category; Rewrite the following statements accurately and explain why the given version is inaccurate and your version is accurate
"Dereferencing memory ...

Rewrite the following statements accurately and explain why the given version is inaccurate and your version is accurate

"Dereferencing memory leaks leads to dangling pointers.”

Can somebody please help me how to write this sentense using right terminology. I am very confused here as we never dereference memory.

Thanks.

My advice is to completely ignore the original statement as it is intentionally wrong and confusing. Do you know what a memory leak is? Do you know what a dangling pointer is? If so, just write about these two concepts and compare/contrast them. The concepts are different, but related.

Describe what you understand of it - then we can fill you in. That's first of all going to make it clear to us what you understand, and avoid us explaining what you already understand, and second, it will show that you are actually willing to work on solving the assignment, rather than simply trying to get someone to do it for you.

memory leak causes because of loosing the access path of it through the pointer,which was previously pointing to that location and now its value is changed. In other words, the pointer which was pointing to it became dangling and this caused this memory leak. In both cases the problem is related to memory ,but I don't understand how come the same problem and what is the problem?

>> In other words, the pointer which was pointing to it became dangling and this caused this memory leak.

Ultimately, you're going to have to pin down your definition of 'dangling' - depending on who you ask, you may get somewhat different answers. One could technically consider a NULL pointer to be dangling (it isn't really a valid address, after all), but I think that the overall consensus is that it is not.

The bottom line is, a memory leak is strictly an accounting issue, while dangling memory is an matter of validity.

In other words, the pointer which was pointing to it became dangling and this caused this memory leak.

No -- by definition, a dangling pointer is pointing to FREE memory. So it cannot be a memory leak. You are seeing two sides of the same coin. In one case, you freed memory and then accessed it. In the other case, you did not free the memory, and did not access it.

You can't logically dereference a memory leak, as that would imply that you still have a valid pointer to derefence, in which case it hasn't leaked (yet). By time its a memory leak, its already been dereferenced, which is why it leaked, because it was dereferenced without being deallocated.

Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

"Dereferenced" doesn't mean what your post implies. Although "a reference has been removed" might be a valid interpretation of the word, it's so strongly against common usage that only confusion can result.