David Smith wrote:
> Pretty straight forward question, right? I'm asking because this is
> one of the recommendations I'm getting from VSTS code analysis.
>
> My problem is that I have a pattern of code sprinkled throughout much
> of my business layer where data access code calls static methods
> that, in turn, call stored procedures that read the selected data
> into newly created DataTables and return these tables. It might be
> difficult to track and dispose of all these tables.
>
> So, how leaky are undisposed of DataTables?
Well, they seem to stay around for quite a while. Just try to
implement calling dispose on a couple of them which are used very
frequently. My tests show that the memory footprint of a large asp.net
application was much lower after I did that (and I used the datatables
in the same way as you do: call a DAL class, that one creates a
datatable, the returned datatable is bound to a repeater etc.). Which
was strange, because the Dispose method in a datatable didn't do much.
It's often impossible to call Dispose on all your data-access code, at
least in some situations.
Do some profiling with the performance monitor of windows and teh .NET
CLR counters available to you and see if it makes a difference, I saw
big differences, but it could be related to the databinding scenario I
used, as binding a datatable to a repeater creates a dataview under the
hood.
FB
--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET:
http://www.llblgen.com
My .NET blog:
http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------