The definiton of "Memory leaks"

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Mar 2005
Posts: 9
Reputation: tenoran is an unknown quantity at this point 
Solved Threads: 0
tenoran tenoran is offline Offline
Newbie Poster

The definiton of "Memory leaks"

 
0
  #1
Mar 23rd, 2005
Could anyone define "Memory leaks" well ?
'cause pretty hard for me to understand with C++ books.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,630
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 718
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: The definiton of "Memory leaks"

 
0
  #2
Mar 23rd, 2005
A memory leak is simply allocating memory and failing to release it when you're done. Technically, the following illustrates a memory leak:
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int *p = new int;
  8.  
  9. *p = 10;
  10.  
  11. cout<< *p << endl;
  12. }
In practice, the operating system will typically reclaim all memory allocated to a process when the process terminates, but that's not required by the language definition. However, long running programs can consume all fast memory and grind the program to a near halt, or crash the system if virtual memory is also exhausted. So any call to new must be paired with a call to delete:
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int *p = new int;
  8.  
  9. *p = 10;
  10.  
  11. cout<< *p << endl;
  12.  
  13. delete p;
  14. }
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 9
Reputation: tenoran is an unknown quantity at this point 
Solved Threads: 0
tenoran tenoran is offline Offline
Newbie Poster

Re: The definiton of "Memory leaks"

 
0
  #3
Mar 28th, 2005
Thank you for the answer.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 489
Reputation: Acidburn is an unknown quantity at this point 
Solved Threads: 5
Acidburn Acidburn is offline Offline
Posting Pro in Training

Re: The definiton of "Memory leaks"

 
0
  #4
Mar 28th, 2005
the best bit is creating a loop of new arrays and watching the memory size increase
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 1,620
Reputation: kc0arf is a jewel in the rough kc0arf is a jewel in the rough kc0arf is a jewel in the rough 
Solved Threads: 51
Team Colleague
kc0arf kc0arf is offline Offline
Posting Virtuoso

Re: The definiton of "Memory leaks"

 
0
  #5
Mar 28th, 2005
Hello Acidburn,

If you are going to do that, be sure to save your work first! I have done some expirements with linux processes, and was able to crash a computer in 20 seconds or so.

Christian
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 489
Reputation: Acidburn is an unknown quantity at this point 
Solved Threads: 5
Acidburn Acidburn is offline Offline
Posting Pro in Training

Re: The definiton of "Memory leaks"

 
0
  #6
Mar 28th, 2005
20 secs? may I have a look at the code? I'm running windows and it just fills up the memory very slowly ...took around 4 hrs! .. .
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC