Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

What are register variables? What are the advantage of using register variables?

1128


What are examples of structures?

1026


What are the scope of static variables?

1116


p*=(++q)++*--p when p=q=1 while(q<=6)

1697


Are there namespaces in c?

1054


What is void main ()?

1011


What are header files and explain what are its uses in c programming?

1065


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

990


Which is the best website to learn c programming?

1031


What is volatile variable in c?

1054


Which is better pointer or array?

974


What is a program flowchart?

1124


Mention four important string handling functions in c languages .

1052


explain what are actual arguments?

1031


Can we add pointers together?

999