Solved

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

Posted on 2016-08-22
3
35 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

749 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