I have been making a C++ application and currently checking if there exists any memory leak before release.

My application will be running as an object over HTTP server and it should be idle until an HTTP request comes in. Which means it should release most of memories when it's idle.

When I checked it using "Visual Leak Detector", there was no memory leak detected and everything was clean.
But when I open "Windows Task Manager" and run the program, the amount of memory in Processes tab keeps increasing everytime HTTP request comes in. (it never decreases after a task done)

Is this a memory leak? Is this a serious problem in case that it runs all the time? How would I fix it?

This looks like a classic case of heap fragmentation. This is a rather classic problem which will cause the memory consumption to grow larger and larger even when the memory that you actually use is not increasing (no leaks). Normally, this will stabilize to a fixed amount of memory consumption after a little while.

To reduce fragmentation, you should, of course, avoid doing lots of dynamic allocations of small chunks of memory. For example, allocating lots of single objects with new is a typical driver of such fragmentation problems. Of course, in C++, you shouldn't be allocating lots of single object with new because there is no need for it, use stack-based local objects instead, and dynamic memory only for arrays (through STL containers).

Comments
VLD is pretty good, so there's no real need to second guess it. Mike's proposition looks correct and is an example of good practice

I haven't used any New stuffs. BUt I have written a lot of:
char* s = "hhh";
char buff[200];
vector<Object> list;
Object objs[10];
std::string str = (string)s + "aaa";

Should I manually release these types of thigns as well?

Edited 3 Years Ago by 9tontruck

Should I manually release them as well?

You can't manually release those. If you didn't create it using new (or malloc), you can't release it using delete (or free).

Edited 3 Years Ago by Moschops

I'm sure it will be optimised this way anyway, but you might want to hint to your compiler that your char* are constants.

const char* s = "123";

Also, your vector, unless given a fixed size, will dynamically allocate memory on the heap internally. This is where your fragmentation may be ocurring.

This article has been dead for over six months. Start a new discussion instead.