Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Experience with dangling refereces or memory leaks. If you have experience with

ID: 3888629 • Letter: E

Question

Experience with dangling refereces or memory leaks. If you have experience with a language like C, C++, or Pascal, in which dynamically allocated space must be manually reclaimed, describe your experience with dangling references or memory leaks. How often do these bugs arise? How do you find them? How much effort does it take? Learn about open source or commercial tools for finding storage bugs (Valgrind is a popular open source example). Do such tools weaken the argument for automatic garbage collection?

Explanation / Answer

Here, I am taking C++ programming language into consideration to answer your question.

A memory leak is a type of resource leak that occurs when a computer program incorrectly manages memory allocations in such a way that memory which is no longer needed is not released.All good C++ programmers know how to avoid leaking memory (or resources like sockets):

Always use smart pointers, i. e.: std::auto_ptr, boost::shared_ptr.

Always be aware of ownership of object: who owns, who refers, who is responsible, etc.

But, memory leaks still happen. Point most common issues when you discovered a memory leak in a program, even when you used the above techniques. Sometimes you forget to define a destructor of base class as virtual. So all derived classes referred by pointer to the base class which was not destroyed properly and therefore leaked.Memory is not freed due to a lost pointer - the last pointer to the memory was cleared before free was called, so there is no way to release it.Memory is not freed due to not properly identifying when the data it contains is no longer needed. An example is a static cache used for some temporary task is never cleared out.

Unit tests are not always the best, or sometimes even a feasible, tool for testing all behavior or reproducing all bugs.

Say I want to follow pure TDD i.e. write unit tests before writing any other code. When I find a bug I must write unit test that reproduces it and then implement a fix. Say there's a memory leak in my application. I can reproduce it - running a particular method 1,000,000,000 times causes OutOfMemoryException. This test takes 10 seconds to fail.

The Garbage Collection page is a comprehensive resource for automatic dynamic memory management. Valgrind is an open-source memory debugger for x86-GNU/Linux. When a program is run under Valgrind's supervision, all reads and writes of memory are checked, and calls to malloc/new/free/delete are intercepted. They have a great range of smart pointers which implement reference counting or delete-on-scope exit or intrusive reference counting. These have proven enough for our needs. A big plus is that it is all free, open source, templated C++. because it is reference counting, in most cases it is highly deterministic when an object gets destroyed.You can no longer use Valgrind, unless you turn the collector off first. While turning the collector off is easy to do, and doesn't require recompiling, it's obviously impossible to use it if you start to run out of memory.

Hence, In my opinion open source tools which are available in market does not weaken the argument for automatic garbage collector untill you are using the right tool for your program.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote