What is a memory leak in structures? How can we rectify that?

Answer Posted / selvaraj

unwanted memory consumed by a program is called memory leak.

Example:

int fact(void)
{
size=melloc(20);
if(size==NULL)
{
return 1;
}
else
{
return 0;
}
}
Explanation:

size=melloc(20);
here the memory reserved
if(size==NULL)
if memory not available
else means memory available return 0
so, throughout the program the size never used but the program reserved the size. this is called memory leak..

to over come this problem in the else part before return 0; add this statement free(s)

Hope you understood. if not u can reach me iamselvam85@gmail.com

Is This Answer Correct ?    13 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why c is a mother language?

560


Some coders debug their programs by placing comment symbols on some codes instead of deleting it. How does this aid in debugging?

660


Are c and c++ the same?

629


a single linked list consists of nodes a to z .print the nodes in reverse order from z to a using recursion

2338


What does s c mean on snapchat?

590






Why c language?

652


What is operator promotion?

635


How can I make it pause before closing the program output window?

585


Explain setjmp()?

662


What is the collection of communication lines and routers called?

616


Explain how do you generate random numbers in c?

628


What is ctrl c called?

601


How can I get back to the interactive keyboard if stdin is redirected?

673


Why c is a procedural language?

587


What is the value of a[3] if integer a[] = {5,4,3,2,1}?

677