Here is my problem, basically I am working on graphs and path finding in C++. I am facing some crashes because I run out of memory. I used a detection leakmemory tool in way to help to find the problem and it occurs in my copyList function :
template<class T>
PElement<T> * PElement<T>::copieListe(PElement<T> * original)
{
if (!original)
{
return NULL;
}
else
{
return new PElement<T>(new T(*original->v),copieListe(original->s));
}
}
Here is the PElement class :
template <class T>
class PElement
{
public :
T * v;
PElement<T> * s;
}
The constructor called in copyList :
template <class T>
PElement<T>::PElement( T * v, PElement<T> * s ):v(v),s(s){}
I am using this function a thousand times... so there needs to be no memory leaks at all. My graphs got a list of egdes and vertex, so you know what is this about :
template <class S, class T>
class Graphe
{
protected:
int prochaineClef;
public:
PElement< Sommet<T> > * lSommets; // liste de sommets (vertices)
PElement< Arete<S,T> > * lAretes; // liste d'arêtes (edges)
}
I know it's not the easiest/best way to do that but it was not my choice, I am just asking if you have idea for how I can limit the memory leak..