Follow Our FB Page << CircleMedia.in >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...

what is memory leak?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

List some applications of c programming language?

215


What is realloc in c?

214


Which programming language is best for getting job 2020?

215


Why void main is used in c?

176


plz let me know how to become a telecom protocol tester. thank you.

1374






What is a shell structure examples?

201


What are run-time errors?

228


Explain logical errors? Compare with syntax errors.

213


Is it possible to use curly brackets ({}) to enclose single line code in c program?

245


What is the function of multilevel pointer in c?

243


When should structures be passed by values or by references?

234


Explain zero based addressing.

230


in ‘C’ language for Matrix Multiplication fails” Introspect the causes for its failure and write down the possible reasons for its failure.

6345


struct screen_pos{ int row, col } ;move_right(cursor)struct screen_pos *cursor;{ cursor.col++; } /* This statementhas a syntax error */What is the correct statement a) cursor.col = cursor.col + 1; b) col.cursor++; c) *cursor.col++; d) pointer

265


Differentiate between calloc and malloc.

259