memory leak?

Apr 16, 2012 at 9:49am
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)
Apr 16, 2012 at 10:37am
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.
Apr 16, 2012 at 2:11pm
http://msdn.microsoft.com/en-us/library/x98tx3cf.aspx

Why are you using such an old version of VS?
Last edited on Apr 16, 2012 at 2:13pm
Apr 17, 2012 at 7:17am
@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).
Apr 18, 2012 at 6:32pm
It is interesting can such debuggers as Valgrind or Deleaker to recognize in this piece of code memory leak? ;)))))
May 19, 2012 at 1:01pm
OMG Is problem solved?
May 19, 2012 at 1:08pm
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.
May 19, 2012 at 1:13pm
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
May 21, 2012 at 5:57pm
_CrtDumpMemoryLeaks rules ;)
Topic archived. No new replies allowed.