Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: C++
Expertise: Beginner
Jan 28, 2000

Memory Leaks and Their Prevention

A memory leak occurs when an application fails for some reason to release dynamic memory that was allocated using new or malloc().The application won't reclaim the allocated memory because both C and C++ assume that if you don't explicitly free dynamically-allocated memory, you want it to remain available throughout the lifetime of the application. Some operating systems reclaim the leaked memory but they do that only after the application has terminated. On other operating systems (DOS, for example) leaked memory is lost until the system is rebooted. In either case, recurrent memory leaks cause an application to bog down or crash altogether. The easiest way to avoid memory leaks is by not using dynamic allocations in the first place. If possible, the application should use automatic and static storage instead of dynamic memory. When dynamic memory allocation is unavoidable, remember to add a matching delete call for every object allocated by new.

Danny Kalev
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap