what is memory leak?

Answers were Sorted based on User's Feedback

what is memory leak? ..

Answer / roshan.p.r.

Consider the following example..

int *p=new int[10];

here ten bytes of memory is allocated and the address is
stored in p. the only way to access this memory is via p.

now suppose if u allocate a new memory to p like

p=new int[20];

the previous address(10 bytes is lost we cant access it
again)because the only way that we had to access it was
pointer p and now a new address(20 bytes) is stored in p.

So we say there is a memory leak.

the best way to handle this is.

int *p=new int[10];
[]delete p;
p=new int[20];

so in the above case we have first released the memory
pointed by p with delete function and then a new address is
assigned to it.

Is This Answer Correct ?    1 Yes 0 No

what is memory leak? ..

Answer / sujith

Memory leak is nothing but u create huge chunk of memory
with a malloc or any such mechanism and u never free that
manually which make the available free main memory in the
system to minimum. this may even lead to system crashing.

Is This Answer Correct ?    1 Yes 1 No

what is memory leak? ..

Answer / tayyab

When two object create a reference to each other. memory
allocated to these objects can not be reclaimed by
operating system even after when all other references are
deleted for these objects.....this concept is called memory

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More C Interview Questions

You are to write your own versions of strcpy() and strlen (). Call them mystrcpy() and mystrlen(). Write them first as code within main(), not as functions, then, convert them to functions. You will pass two arrays to the function in the case of mystrcpy(), the source and target array.

0 Answers  

What are pointers in C?

5 Answers   KPIT,

Is the C language is the portable language...If yes...Then Why...and if not then what is problem so it is not a Portable language..???

2 Answers   TCS,

what is the use of getch() function in C program.. difference b/w getch() and getche()??

29 Answers   IBM, Wipro, Infosys, TCS, HCL,

What will be printed as the result of the operation below: #include<..> int x; int modifyvalue() { return(x+=10); } int changevalue(int x) { return(x+=1); } void main() { int x=10; x++; changevalue(x); x++; modifyvalue(); printf("First output:%d\n",x); x++; changevalue(x); printf("Second output:%d\n",x); modifyvalue(); printf("Third output:%d\n",x); }

2 Answers  

what are two kinds of java

2 Answers  

Write a C++ program to give the number of days in each month according to what the user entered. example: the user enters June the program must count number of days from January up to June

0 Answers  

1. What will be the output of the following programs. a) #include <stdio.h> Main() { Int x=4; While(x==1) { X=x-1; Printf(“%d”,x); --x; } }

7 Answers   CSC,

write a program to interchange the value between two variable without using loop

1 Answers  

Write a C program that computes the value ex by using the formula ex =1+x/1!+x2/2!+x3+3!+………….

1 Answers  

#include <stdio.h> int main() { int i; for (i=0;i<3;++i) { fork();fork(); } } How many processes are created when running this program (including the initial one)? Explain &#1567;&#1567;&#1567;

4 Answers  

What is difference between the following 2 lines…. int temp = (int)(0x00); int temp = (0x00int);

3 Answers   Bosch,