Hi All,

I am using CStringArray object in VC++ 6.0 application. Trying to
release this object by .RemoveAll() function. But, it is decreasing the "VM
Size" from task manager. And, I confirmed this with memory leak tool.

The "VM Size" after loading all the CString objects into CStringArray is
17MB. After RemoveAll() called, it decreases just 1MB.

And, same for CArray and CMap objects also. How to deallocate them
successfully?

All objects are member variables of class. There is no global objects.

What is the difference between "Mem Usage" and "VM Size" in task
manager? If I minimize the application, "Mem Usage" decreases to 1MB from 20
MB. But, "VM Size" is not decreasing. Can anybody clear this doubt.

Please suggest.

Thanks in advance.

Regards,

Re: CStringArray, CArray and CMap objects have memory leak? by Doug

Doug
Thu Jul 17 09:56:52 CDT 2008

On Thu, 17 Jul 2008 19:18:54 +0530, "John" <john@microsoft.discussions.com>
wrote:

>Hi All,
>
> I am using CStringArray object in VC++ 6.0 application. Trying to
>release this object by .RemoveAll() function. But, it is decreasing the "VM
>Size" from task manager. And, I confirmed this with memory leak tool.
>
> The "VM Size" after loading all the CString objects into CStringArray is
>17MB. After RemoveAll() called, it decreases just 1MB.
>
> And, same for CArray and CMap objects also. How to deallocate them
>successfully?

The freed memory remains in your heap as committed regions of your address
space, which is not a problem. There's nothing more you can do other to
abandon new and malloc and write your own heap manager based on the
VirtualXXX API; you'll probably also need to provide a compaction feature
so that you will be able to release significant amounts of address space,
but compaction doesn't play well when working with plain pointers as
opposed to handles. The standard state of affairs isn't nearly bad enough
to warrant doing this; the only real problem is the possibility of
fragmentation limiting future large allocations, and in general, you need
compaction to deal with that.

> All objects are member variables of class. There is no global objects.
>
> What is the difference between "Mem Usage" and "VM Size" in task
>manager? If I minimize the application, "Mem Usage" decreases to 1MB from 20
>MB. But, "VM Size" is not decreasing. Can anybody clear this doubt.

The difference probably has something to do with Windows trimming your
process's working set when you minimize it. You can probably find out more
by reading Russinovich.

--
Doug Harrison
Visual C++ MVP