GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Interview Questions  >  Programming  >  C++

 Print  |  
Question:  What is a memory leak? How can we avoid it?



July 07, 2006 12:22:07 #3
    Member Since: Visitor    Total Comments: N/A 

RE: What is a memory leak? How can we avoid it?
 

When dynamic memory allocation is used extensively, memory leak may occur.It happens when first memory block is not deleted . However, the address is lost because the pointer contains the address of second block.The memory leak is unintentional occupied memory. It can de avoided by using delete statement.

example:

float *ptr=new float

*ptr=6.0;//Access first block

'Use delete statement --"delete ptr";Otherwise it will cause memory leak

ptr=new float

*ptr=7.0//Acess second block

     

 

Back To Question