Memory leak

F

Frank Rizzo

Hello, I have a very frustrating issue I've been working on. I have a
routine that does the following:

1. Load a large (declared local to the function) DataSet from the
database. It contains 5 tables.
2. Load the database into a fairly complicated object model.
3. I dispose of the Dataset.

Before loading the DataSet the MemUsage column in Task Manager shows 44
MB. After loading the database the MemUsage stands at 59 MB. Thus I
assume that the DataSet has about 15 MB of data, which is about right.

I then load the DataSet data into an object model and the MemUsage jumps
to 84 MB, thus the object model weighs about 25 MB, which is also about
right.

I then dispose of the DataSet, but the MemUsage column does not change.
I've tried GC.Collect, GC.WaitForPendingFinalizers, DataSet.Clear,
etc... but nothing helps.

Why won't the DataSet release memory? There is a definite leak of 15
MB, which wouldn't be a problem, except that this routine is run by
multiple threads, which multiplies the problem quite a bit.

This is VS2003 and .NET 1.1. I've found a discussion where a claim is
made by someone else that DataSet doesn't release memory, but nothing
specific is offered (
http://www.dotnet247.com/247reference/msgs/35/178959.aspx ). Any
guidance on this subject would be appreciated.

Regards.
 
J

john sun

Frank said:
Hello, I have a very frustrating issue I've been working on. I have a
routine that does the following:

1. Load a large (declared local to the function) DataSet from the
database. It contains 5 tables.
2. Load the database into a fairly complicated object model.
3. I dispose of the Dataset.

Before loading the DataSet the MemUsage column in Task Manager shows 44
MB. After loading the database the MemUsage stands at 59 MB. Thus I
assume that the DataSet has about 15 MB of data, which is about right.

I then load the DataSet data into an object model and the MemUsage jumps
to 84 MB, thus the object model weighs about 25 MB, which is also about
right.

I then dispose of the DataSet, but the MemUsage column does not change.
I've tried GC.Collect, GC.WaitForPendingFinalizers, DataSet.Clear,
etc... but nothing helps.

Why won't the DataSet release memory? There is a definite leak of 15
MB, which wouldn't be a problem, except that this routine is run by
multiple threads, which multiplies the problem quite a bit.

This is VS2003 and .NET 1.1. I've found a discussion where a claim is
made by someone else that DataSet doesn't release memory, but nothing
specific is offered (
http://www.dotnet247.com/247reference/msgs/35/178959.aspx ). Any
guidance on this subject would be appreciated.

Regards.

Have you tried to use the process explorer,
http://www.microsoft.com/technet/sysinternals/utilities/ProcessExplorer.mspx

There is a column called private bytes, and you can use that column to
track how many memory your application is really using.

The mem usage column used by the task manager is the actual working set
size of the process, it includes the shared memory and all the memory
used by a lot of system resource. In the .Net case, it includes the
memory used by the framework.

HTH.
J.W.
 
K

Kevin Yu [MSFT]

Hi Frank,

From your description, I don't think there is a memory leak in this app,
based on the following reasons.

1. The mem usage column is not an accurate number that your app is actually
using. This is a counter for the physical memory the app is using. Since
windows paging technism may swap some memory to your hard disk. This
counter is not reliable for calculating the actual memory usage. You can
check the VS Size by selecting it in Select Column in Task Manager.
2. Please make sure that there are no object or object members holding a
reference to the DataSet or its members. Or the memory will not be
released.
3. Garbage collection will be performed when memory is not enough. So
generally, it will not come up when your DataSet goes out of scope.
Although you can call GC.Collect to force a barbage collection of all
generations. However, the Collect method does not guarantee that all
inaccessible memory is reclaimed.

http://www.coversant.net/dotnetnuke/Default.aspx?tabid=88&EntryID=4

If your VM Size does keep going bigger and bigger after it is running for
some hours or days and result in an OutOfMemoryException, this will not be
a memory leak. You can test it again. If there is anything unclear, please
feel free to let me know.

Kevin Yu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
K

Kevin Yu [MSFT]

Hi Frank,

I'd like to know if this issue has been resolved yet. Have you checked the
last reply I made? Is there anything that I can help. I'm still monitoring
on it. If you have any questions, please feel free to post them in the
community.

Happy new year!

Kevin Yu
Microsoft Online Community Support
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top