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
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
>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.
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
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.
You can also use smart-pointer technique.
template <class T>
class auto_ptr
{
private:
T* ptr;
public:
explicit auto_ptr(T* p = 0) : ptr(p) {}
~auto_ptr() {delete ptr;}
T& operator*() {return *ptr;}
T* operator->() {return ptr;}
};
I advise you to use some memory leaks detection tools. For example: Deleaker or Valgrind (forgot link)
Great tools:ooh:
I usually use deleaker :icon_smile: to debug a memory leak in C + +. I do not like integrated debugger.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.