Memory Leaks

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: May 2005
Posts: 21
Reputation: gpta_varun is an unknown quantity at this point 
Solved Threads: 0
gpta_varun gpta_varun is offline Offline
Newbie Poster

Memory Leaks

 
0
  #1
Mar 23rd, 2006
Hi

Is there any way , memory leaks can be clogged in c/c++ ...

Are there any good tutorials on how can we make our code Memory Leak free ??/

Best Regards

-Varun
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,868
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: 755
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: Memory Leaks

 
0
  #2
Mar 23rd, 2006
>Is there any way , memory leaks can be clogged in c/c++ ...
Knowledge and discipline. If you're aware of how memory leaks can come about in your project and apply a disciplined approach to avoid them, that's all you need.

>Are there any good tutorials on how can we make our code Memory Leak free ??/
Probably, but I don't know of any off hand.
New members chased away this month: 5
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 89
Reputation: msaqib is an unknown quantity at this point 
Solved Threads: 1
msaqib msaqib is offline Offline
Junior Poster in Training

Re: Memory Leaks

 
0
  #3
Mar 23rd, 2006
Wel after googling for some time I came across this link
http://www.linuxjournal.com/article/6556
It stats using some tools you can prevent memory leaks.

Here is a C++ Memory Management tutorial.
http://www.mycplus.com/cplus.asp?CID=42
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,678
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1504
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Memory Leaks

 
0
  #4
Mar 23rd, 2006
A lot depends on the program you are writing. Two hints:
1. Using c++ std container classes instead of C-style dynamically allocated objects is the first place to start -- assuming your compiler supports those container classes, not all c++ compilers do.
2. If you are writing Microsoft Windows programs you have to be careful about the system-wide resources that your program allocates, make sure the program frees/releases the resources before terminating.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 464
Reputation: invisal is a jewel in the rough invisal is a jewel in the rough invisal is a jewel in the rough 
Solved Threads: 49
invisal's Avatar
invisal invisal is offline Offline
Posting Pro in Training

Re: Memory Leaks

 
0
  #5
Aug 3rd, 2009
You can also use smart-pointer technique.

  1. template <class T>
  2. class auto_ptr
  3. {
  4. private:
  5. T* ptr;
  6. public:
  7. explicit auto_ptr(T* p = 0) : ptr(p) {}
  8. ~auto_ptr() {delete ptr;}
  9. T& operator*() {return *ptr;}
  10. T* operator->() {return ptr;}
  11. };
Last edited by invisal; Aug 3rd, 2009 at 3:43 pm.
Yesterday is a history, tomorrow is a mystery, today is a gift.
Behind every smile is a tear.
Visal .In
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 6
Reputation: JAGjug is an unknown quantity at this point 
Solved Threads: 0
JAGjug JAGjug is offline Offline
Newbie Poster

Re: Memory Leaks

 
0
  #6
Sep 28th, 2009
I advise you to use some memory leaks detection tools. For example: Deleaker or Valgrind (forgot link)
Reply With Quote Quick reply to this message  
Reply

Message:




Views: 1360 | Replies: 5
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC