• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 97
  • Last Modified:

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

I had this question after viewing Find dangling pointer or lost heap-dynamic  variables..
0
priscilla ammisetti
Asked:
priscilla ammisetti
1 Solution
 
priscilla ammisettiAuthor Commented:
tel me very fast pls
0
 
phoffricCommented:
• 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
 
frankhelkCommented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now