Answer to Question #157632 in C++ for zain ul abdeen

Question #157632

What is memory leak, and dangling pointer?


1
Expert's answer
2021-01-29T04:16:43-0500

Memory Leak

In computer science, a memory leak occurs when a computer program incorrectly manages memory allocations. As per simple we have allocated the memory and not Free other language term say not release it call memory leak it is fatal to application and unexpected crash.

char *myarea=(char *)malloc(10);

char *newarea=(char *)malloc(10);

myarea=newarea;



Dangling Pointer

If any pointer is pointing the memory address of any variable but after some variable has deleted from that memory location while pointer is still pointing such memory location. Such pointer is known as dangling pointer and this problem is known as dangling pointer problem.

#include<stdio.h>

  int *call();

  void main(){

      int *ptr;
      ptr=call();

      fflush(stdin);
      printf("%d",*ptr);

   }

 int * call(){

   int x=25;
   ++x;
   return &x;
 }




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS