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=0;
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
leak

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More C Interview Questions

Write a code to determine the total number of stops an elevator would take to serve N number of people.

0 Answers   Expedia,


What is structure pointer in c?

0 Answers  


what is the little endian and big endian?

1 Answers  


Why c++ is called c++ and not c+?

9 Answers   EBS,


To what value are pointers initialized? 1) NULL 2) Newly allocated memory 3) No action is taken by the compiler to initialize pointers.

4 Answers   Aricent,






Can a program have two main functions?

0 Answers  


Write a program that takes a 5 digit number and calculates 2 power that number and prints it.

1 Answers  


if array a conatins 'n' elements and array b conatins 'n-1' elements.array b has all element which are present in array a but one element is missing in array b. find that element.

18 Answers   Parexel, Ram Infotech, Zycus Infotech,


Explain how do you view the path?

0 Answers  


Reverse a string word by word??

9 Answers  


Can an array be an Ivalue?

0 Answers   EXL,


Differentiate between new and malloc(), delete and free() ?

0 Answers   iNautix,


Categories