Hi all,

I am able to release the resources (CStringArray objects) in debug
mode. But, not in Release mode.

Any project settings or compiler options are required?

Thanks and Regards,
John

Re: Debug vs Release mode - memory leak by Alf

Alf
Tue Jul 22 00:26:54 CDT 2008

* John:
>
> I am able to release the resources (CStringArray objects) in debug
> mode. But, not in Release mode.
>
> Any project settings or compiler options are required?

Hi.

Try to create a *minimal* program that exhibits the problem. If that doesn't
help you, try posting that example here.

How are you checking whether your resources are released?

Are there any suspicious ASSERTs or the likes? Note that such code is removed
in a release build.

Cheers, & hth.,

- Alf


--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

Re: Debug vs Release mode - memory leak by John

John
Tue Jul 22 00:45:48 CDT 2008

Hi Alf P. Steinbach,

Thank you for your prompt reply.

I have checked with some memory leak tools. But they could not identify
the leaks which are due to CStringArray objects.
I debugged line by line and paralelly checking in "VM Size" in task manager.
After calling .RemoveAll(), it dint decrease the memory. When adding strings
to this array, it is increasing the memory but not decreasing with
RemoveAll(). If I allocate on heap, it is deallocating the resources. But, I
cannot replace all CStringArray objects with TCHAR** object. This
application s there in production. How to achieve this?

I tried to simulate this in sample application. It is working fine. Any
limitations are there with CStringArray?

In this application, lot of CStringArray and CMap objects are there. Can
MFC manage if plenty of CStringArray and CMap objects in the application?

Please guide me.

Thanks and Regards,
John.

"Alf P. Steinbach" <alfps@start.no> wrote in message
news:8aOdncuerrUD8hjVnZ2dnUVZ_t3inZ2d@posted.comnet...
>* John:
>>
>> I am able to release the resources (CStringArray objects) in debug
>> mode. But, not in Release mode.
>>
>> Any project settings or compiler options are required?
>
> Hi.
>
> Try to create a *minimal* program that exhibits the problem. If that
> doesn't help you, try posting that example here.
>
> How are you checking whether your resources are released?
>
> Are there any suspicious ASSERTs or the likes? Note that such code is
> removed in a release build.
>
> Cheers, & hth.,
>
> - Alf
>
>
> --
> A: Because it messes up the order in which people normally read text.
> Q: Why is it such a bad thing?
> A: Top-posting.
> Q: What is the most annoying thing on usenet and in e-mail?



Re: Debug vs Release mode - memory leak by Alex

Alex
Tue Jul 22 07:14:50 CDT 2008

"John" wrote:
> I have checked with some memory leak tools. But they could
> not identify the leaks which are due to CStringArray objects.

Your tools are correct.

> I debugged line by line and paralelly checking in "VM Size" in
> task manager. After calling .RemoveAll(), it dint decrease the
> memory. When adding strings to this array, it is increasing the
> memory but not decreasing with RemoveAll().

Task Manager is the wrong tool for detecting memory leaks. The
memory, which is deallocated in CStringArray is not released to
the system immediately. Instead, memory manager holds it for
future allocation requests, so no new memory is allocated from OS.
This is perfectly normal behaviour.

Alex



Re: Debug vs Release mode - memory leak by John

John
Tue Jul 22 08:36:09 CDT 2008

Ok.

then
what is low virtual memory and how can I resolve this?

and one more thing, it is fine in debug mode.

Please try with the below sample code in sample application
(win32application + mfc support) for debug and release mode:

code:
CStringArray oArr;

for (int a = 0; a < 1000000; a ++)
{
CString str;
str.Format(TEXT("this is text .... %d"),a );
oArr.Add(str);
}
AfxMessageBox(TEXT("Before RemoveAll()")); //Check task manager
oArr.RemoveAll();
AfxMessageBox(TEXT("After RemoveAll()"));//check task manager


Thanks and Regards,
John.

"Alex Blekhman" <tkfx.REMOVE@yahoo.com> wrote in message
news:OoQBMS$6IHA.2260@TK2MSFTNGP03.phx.gbl...
> "John" wrote:
>> I have checked with some memory leak tools. But they could not
>> identify the leaks which are due to CStringArray objects.
>
> Your tools are correct.
>
>> I debugged line by line and paralelly checking in "VM Size" in task
>> manager. After calling .RemoveAll(), it dint decrease the memory. When
>> adding strings to this array, it is increasing the memory but not
>> decreasing with RemoveAll().
>
> Task Manager is the wrong tool for detecting memory leaks. The memory,
> which is deallocated in CStringArray is not released to the system
> immediately. Instead, memory manager holds it for future allocation
> requests, so no new memory is allocated from OS. This is perfectly normal
> behaviour.
>
> Alex
>



Re: Debug vs Release mode - memory leak by John

John
Tue Jul 22 08:39:03 CDT 2008

Which is the best memory leak tool?

"Alex Blekhman" <tkfx.REMOVE@yahoo.com> wrote in message
news:OoQBMS$6IHA.2260@TK2MSFTNGP03.phx.gbl...
> "John" wrote:
>> I have checked with some memory leak tools. But they could not
>> identify the leaks which are due to CStringArray objects.
>
> Your tools are correct.
>
>> I debugged line by line and paralelly checking in "VM Size" in task
>> manager. After calling .RemoveAll(), it dint decrease the memory. When
>> adding strings to this array, it is increasing the memory but not
>> decreasing with RemoveAll().
>
> Task Manager is the wrong tool for detecting memory leaks. The memory,
> which is deallocated in CStringArray is not released to the system
> immediately. Instead, memory manager holds it for future allocation
> requests, so no new memory is allocated from OS. This is perfectly normal
> behaviour.
>
> Alex
>



Re: Debug vs Release mode - memory leak by Alex

Alex
Tue Jul 22 09:56:25 CDT 2008

"John" wrote:
> then what is low virtual memory and how can I resolve this?

It means that your program tries to allocate more than the system
can provide. Increase the page file size or allocate less.

> Please try with the below sample code in sample application
> (win32application + mfc support) for debug and release mode:
> [...]

There is nothing wrong with this code.

Alex



Re: Debug vs Release mode - memory leak by Alex

Alex
Tue Jul 22 09:58:51 CDT 2008

"John" wrote:
> Which is the best memory leak tool?

Depends on your needs. Here is the list of common memory
debuggers:

"Memory debugger"
http://en.wikipedia.org/wiki/Memory_debugger

HTH
Alex



Re: Debug vs Release mode - memory leak by Doug

Doug
Tue Jul 22 10:32:55 CDT 2008

On Tue, 22 Jul 2008 11:15:48 +0530, "John" <john@microsoft.discussions.com>
wrote:

> I have checked with some memory leak tools. But they could not identify
>the leaks which are due to CStringArray objects.
>I debugged line by line and paralelly checking in "VM Size" in task manager.
>After calling .RemoveAll(), it dint decrease the memory. When adding strings
>to this array, it is increasing the memory but not decreasing with
>RemoveAll(). If I allocate on heap, it is deallocating the resources. But, I
>cannot replace all CStringArray objects with TCHAR** object. This
>application s there in production. How to achieve this?
>
> I tried to simulate this in sample application. It is working fine. Any
>limitations are there with CStringArray?
>
> In this application, lot of CStringArray and CMap objects are there. Can
>MFC manage if plenty of CStringArray and CMap objects in the application?
>
> Please guide me.

I explained this to you in my reply to your message in this group of Jul
17, with subject "Debug vs Release mode - memory leak". Did you miss it?
Was it unclear?

--
Doug Harrison
Visual C++ MVP