memory leak?

I'm a little confused about why I don't get a memory leak:
I use Microsoft Visual Studio 2005, C++, progamming a console application.

I use a class:

template <typename T> CSomeData{
...
T* *m_data
...
}

I define an instance

CSomeData<string> A;

which is filled with some string-pointers during the runtime. The destructor looked like:

template <typename T> ~CSomeData{
...
for(i=0;i<m_data_n;i++)
delete m_data[i];
delete [] m_data;
...
}

This worked without any problems. During debuging I changed this code, namely I just left the destructor empty. I expected a memory leak but nothing like that happend. The program terminated normally and the output didn't tell about any memory leaks. (The strings in the data are not deleted from any other function.)

Why is that?
Is there some kind of inherit garbige collector by some of the libraries I use (stdio, tchar, string, vector, strstream, iostream)?
Or is it because the class is a template class and thus is compiled in a different way?
Or is the Visual Studio Output so stupid not to tell me about the leaks? (but that would be strange since I remember it telling about memory leaks - but that was a slightly earlier version of Visual Studio)
If it's a memory leak or not depends on how you are allocating your data. The rule is that if you allocate something with new you have to deallocate it with delete.

template <typename T> CSomeData{ Shouldn't the class keyword be here? Or is it a bad copy paste?

I don't know if Visual Studio reports memory leaks. If it do, it probably only do it in debug mode so make sure you run you program in debug mode.
http://msdn.microsoft.com/en-us/library/x98tx3cf.aspx

Why are you using such an old version of VS?
Last edited on
@cire:
1. thx, that was really helpful!
2. I'm not a programmer but just use C++ to solve some problems which are not ideal to be solved with Matlab or similar. VS 2005 provided everything I needed thus I never bothered to update it (always risking that the new versions provides some features that I don't like and cannot be switched off).

@Peter87: bad copy paste (of course).
It is interesting can such debuggers as Valgrind or Deleaker to recognize in this piece of code memory leak? ;)))))
OMG Is problem solved?
It seems you did not define copy constructor and the copy assignment operator. So the compiler uses default special functions. This is the reason of the memory leak.
Well, did you enable memory leaks detection first ? (in debug configuration, of course). This is required step.
http://msdn.microsoft.com/en-us/library/e5ewb1h3(v=vs.80).aspx
_CrtDumpMemoryLeaks rules ;)
Topic archived. No new replies allowed.