memory problems

I am using VS2008.
I have a Windows Service application which creates Crystal Reports. This is
a multi theaded application which can run several reports at one time.
My problem - there is a memory leak someplace. I can not detect the memory
leak by running several reports by hand, but when I run tha app as a
servrice and process few hundred reports there is significant memory leak.
The application can consume over 1GB of memory where it should not go over
200 mb. I have few other applications that use Crystal Reports and those
applications do not have memory leak, the big difference is those
applications are single threaded.

My question: are there any tools, books, tutorials that can help me to find the memory leak?

There aren't any book, or tool which can help you find and solve your memory leak problem rapidly and directly. :)
But the cause : Yes. Here are several causes :
1- You allocated dynamic memory (pointers) but you forgot to delete (free) them.
2- Your structures have a lot of members, probably this means not all variables are used completely, so also it may cause memory leak.

However, you cannot easily debug a windows service as it is, just debug your EXE as any normal console applicaton (it could be required to first change your application code to be able to do that, it depends how it is written)

I can recommend to read a book "Effective C++" and you can read in wikipedia or softpedia about different debuggers (VLD, Purifu, MemCheck, DrMemory, Deleaker). Also, read about object oriented programming.

"Block code" in my opinion is the code which is only used to debug (usually complex programs) that standard debug feature cannot.
Some functions which can do this effectively (which I'm currently using in many big projects) :

It's possible to prevent memory leaks by simply being careful. The example code provided by Jackson Marie intentionally (I hope) shows lack of care and logic. In general, allocating different blocks of memory is a good way to leak memory unless you utilise the use of smart pointers. However, common solutions are memory pools or garbage collection.

A memory pool is a large pre-allocated block of memory that is capable of storing any type of information. This pool of memory is normally managed by an interface which the program uses to store its data. Memory pools themselves do not leak if the pool is released. However, if an object's constructor is called, the corresponding destructor must be called.

A garbage collection system is a system that automatically frees allocated memory which saves the programmer from developing time-consuming memory management systems. A leaking GBS almost never happens.

My opinion on GBSs:
They do save the programmer time, but they don't teach proper discipline of memory like C/C++ does. Personally, I avoid GB at all costs; it's bad for my mental well-being.

Just out of interest: When you say RAII, at present it's mostly done so by using smart pointers and STL containers as you showed right? I mean as opposed to opening a resource (or initialising a pointer) in the constructor (and providing fail safety there) and cleaning it up in the destructor?

> Just out of interest: When you say RAII, at present it's mostly done so
> by using smart pointers and STL containers as you showed right?

Yes. The standard library also provides RAII mechanisms for other resources that it encapsulates; for example std::lock_guard and friends.

> as opposed to opening a resource (or initialising a pointer) in the constructor (and providing fail safety there)
> and cleaning it up in the destructor?

In many programs, we have to deal with resources that are not provided by the standard library. For example, there may be a database library written in C that we want to use. And it has the usual suite of sandwich functions: