Why DataSet not out of scope?

G

Guest

Say you create a DataSet in a function in your Data Access layer, then pass
it back to your business layer, why is it not out-of-scope in your business
layer?

If you look at the below article, it states
"If you declare a variable within a procedure, but outside of any If
statement, the scope is until the End Sub or End Function. The lifetime of
the variable is until the procedures ends."

http://msdn2.microsoft.com/en-us/library/ms973875.aspx
 
H

Hans Kesting

Billy expressed precisely :
Say you create a DataSet in a function in your Data Access layer, then pass
it back to your business layer, why is it not out-of-scope in your business
layer?

If you look at the below article, it states
"If you declare a variable within a procedure, but outside of any If
statement, the scope is until the End Sub or End Function. The lifetime of
the variable is until the procedures ends."

http://msdn2.microsoft.com/en-us/library/ms973875.aspx

The *variable* may be out of scope, but that doesn't automatically
invalidate the object that is was pointing to.
Your function returns a DataSet (or rather a reference to that DataSet)
so the dataset will remain "alive" as there still is a reference to it.
And you *have* that reference (the return value from your Data Access
call), so you can still access that DataSet.

If you don't keep that reference somehow, the dataset the variable was
pointing to will be eligible for garbage collection as soon as the
(last) variable pointing to it goes out of scope.

Hans Kesting
 

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

Top