I trying to determine the best pattern for designing my business and data
layers...
Can the instance of the business object eventually cause memory leaks in
Example 1? If your business class doesn't implement IDisposable and falls
out scope, does it eventually get cleaned up by the GC or should it be set to
NULL?
If it can cause leaks, should the IDisposable always be implemented at a
base class level as a best practice?
If it does implement IDisposable, is wrapping the using statement (Example
2) in a try block to catch any exceptions the proper technique? I see
samples of "using" but not many of how to handle an exception if it occurs in
the using block.
EXAMPLE 1
-------------
MyBizClass myBizClass = null;
try
{
myBizClass = new MyBizClass();
return myBizClass.GetSomeDataFromDataLayer();
}
catch
{
throw;
}
finally
{
//Set myBizClass = null???
}
EXAMPLE 2
--------------
try
{
using (MyBizClass myBizClass = new MyBizClass())
{
return myBizClass.GetSomeDataFromDataLayer();
}
}
catch
{
throw;
}