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.

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)

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.