Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   Dispose variables to free memory (http://www.velocityreviews.com/forums/t732664-dispose-variables-to-free-memory.html)

Big George 09-06-2010 07:14 PM

Dispose variables to free memory
 
Hello,
I don't get it how to use Dispose in ASP.NET 1.1.

On MyClass, I put my own Dispose procedure. I instance MyClass as
oMyClass, I use it and after I finish, I call oMyClass.Dispose,
looking for releasing memory.

Repeater1 stores and shows properties from oMyClass. But after doing
oMyClass.Dispose, Repeater1 shows oMyClass.properties with no value

- Am I doing wrong the dispose function?
- If leave Dispose method on MyClass and don't call it, will .NET
still dispose all variables or not?


'On my aspx code behind I put:

'''' Code behind
myArray = New ArrayList

Do While dataRead.Read
oMyClass = New MyClass()
myArray.Add(oMyClass)
oMyClass.Dispose()
Loop
dataRead.Dispose

Repeater1.DataSource = myArray
Repeater1.DataBind()
'Repetear1 shows properties from MyClass
'''' Code behind


'''' MyClass code:
Public Class MyClass
Implements IDisposable
Private mproperty1 as string
Private mproperty2 as string

Private disposedValue As Boolean = False

Protected Overridable Sub Dispose(ByVal disposing As Boolean)
If Not Me.disposedValue Then
If disposing Then
mproperty1=""
mproperty2=""
End If

End If
Me.disposedValue = True
End Sub

Public Sub Dispose() Implements IDisposable.Dispose

Dispose(True)
GC.SuppressFinalize(Me)
End Sub

Public Sub ProcedureToFillMyProperties
....
End Sub

Public ReadOnly Property Property1() As String
Get
Return mproperty1
End Get
End Property

Public ReadOnly Property Property2() As String
Get
Return mproperty2
End Get
End Property

End Class

Cubaman 09-07-2010 07:33 AM

Re: Dispose variables to free memory
 
On Sep 6, 9:14*pm, Big George <jbet...@gmail.com> wrote:
> Hello,
> I don't get it how to use Dispose in ASP.NET 1.1.
>
> On MyClass, I put my own Dispose procedure. I instance MyClass as
> oMyClass, I use it and after I finish, I call oMyClass.Dispose,
> looking for releasing memory.
>
> Repeater1 stores and shows properties from oMyClass. But after doing
> oMyClass.Dispose, Repeater1 shows oMyClass.properties with no value
>
> - Am I doing wrong the dispose function?
> - If leave Dispose method on MyClass and don't call it, will .NET
> still dispose all variables or not?
>
> 'On my aspx code behind I put:
>
> '''' Code behind
> myArray = New ArrayList
>
> Do While dataRead.Read
> * *oMyClass = New MyClass()
> * *myArray.Add(oMyClass)
> * *oMyClass.Dispose()
> Loop
> dataRead.Dispose
>
> Repeater1.DataSource = myArray
> Repeater1.DataBind()
> 'Repetear1 shows properties from MyClass
> '''' Code behind
>
> '''' MyClass code:
> Public Class MyClass
> * *Implements IDisposable
> * *Private mproperty1 as string
> * *Private mproperty2 as string
>
> * *Private disposedValue As Boolean = False
>
> * *Protected Overridable Sub Dispose(ByVal disposing As Boolean)
> * * * * * * If Not Me.disposedValue Then
> * * * * * * * * If disposing Then
> * * * * * * * * * * mproperty1=""
> * * * * * * * * * * mproperty2=""
> * * * * * * * * End If
>
> * * * * * * End If
> * * * * * * Me.disposedValue = True
> * *End Sub
>
> * *Public Sub Dispose() Implements IDisposable.Dispose
>
> * * * * *Dispose(True)
> * * * * *GC.SuppressFinalize(Me)
> * *End Sub
>
> * *Public Sub ProcedureToFillMyProperties
> * * * ....
> * *End Sub
>
> * *Public ReadOnly Property Property1() As String
> * * * * * * Get
> * * * * * * * * Return mproperty1
> * * * * * * End Get
> * *End Property
>
> * *Public ReadOnly Property Property2() As String
> * * * * * * Get
> * * * * * * * * Return mproperty2
> * * * * * * End Get
> * *End Property
>
> End Class


Hello:
Dispose is used in classes that holds unmanaged or high resource
consuming members. Like DDBB connections, graphics objects, etc. If
your class only holds a couple of strings, it's unnecessary to make it
IDisposable. If you want, use .Net Reflector and take a look at how
it's implemented in SqlConnection class, for example.
http://www.red-gate.com/products/reflector/
Best regards.


All times are GMT. The time now is 12:46 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.