Solved

what is lost heap dynamic? and how it is created. explain indetail

Posted on 2016-08-22
3
21 Views
Last Modified: 2016-11-28
I had this question after viewing Find dangling pointer or lost heap-dynamic  variables..
0
Comment
Question by:priscilla ammisetti
3 Comments
 

Author Comment

by:priscilla ammisetti
ID: 41766313
tel me very fast pls
0
 
LVL 32

Accepted Solution

by:
phoffric earned 500 total points
ID: 41766338
• Lost heap-dynamic variable (garbage)
– An allocated heap-dynamic variable that is no longer accessible to the user program
• Pointer p1 is set to point to a newly created heap-dynamic variable
• Pointer p1 is later set to point to another newly created heap dynamic variable
• We now have a memory leak
http://aturing.umcs.maine.edu/~meadow/courses/cos301/cos301-6b.pdf

If you say Type *ptr = new Type; and then say ptr = NULL;
then the allocation of the Type object is not longer available. The memory is still allocated on the heap, but the program has lost permanent access to it. It is just taking up memory and will not be released until the program ends.

In the above scenario, if you are in a loop doing the new and the ptr = NULL; then the program's memory usage keeps increasing as more Type objects are thrown away on the heap. You have to delete the Type object before setting ptr to NULL.
0
 
LVL 14

Expert Comment

by:frankhelk
ID: 41903858
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Accept: phoffric (https:#a41766338)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

frankhelk
Experts-Exchange Cleanup Volunteer
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question