Re: Why DataSet not out of scope?



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


.



Relevant Pages

  • Re: memory leak or not?
    ... CAN get GC'd BEFORE the reference, pointing to this instance, leaves it's ... lexicaly-enclosing method scope". ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: VB.net 03, run one project from another
    ... How are you adding the reference? ... I have a business layer that has a bunch of business objects ... "Scott M." wrote: ... I am also self taught thus far with programming. ...
    (microsoft.public.dotnet.general)
  • Re: VB.net 03, run one project from another
    ... How are you adding the reference? ... I have a business layer that has a bunch of business objects ... Unfortunately, I have tried that, and I get an error message that the ... "Scott M." wrote: ...
    (microsoft.public.dotnet.general)
  • Re: VB.net 03, run one project from another
    ... "RobinS" wrote: ... Are you using the Projects tab under the References? ... But when I add the reference, ... I have a business layer that has a bunch of business ...
    (microsoft.public.dotnet.general)
  • Re: ICC double standards to the fore
    ... gesture as the code requires. ... verdict which makes no reference to "pointing or gesturing" which the ... despite which Zaheer Khan was docked 80%. ... thanks for "pointing" that out. ...
    (rec.sport.cricket)