Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Dispose variables to free memory

Reply
Thread Tools

Dispose variables to free memory

 
 
Big George
Guest
Posts: n/a
 
      09-06-2010
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
 
Reply With Quote
 
 
 
 
Cubaman
Guest
Posts: n/a
 
      09-07-2010
On Sep 6, 9:14*pm, Big George <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to dispose session variables automatically Andy Fish ASP .Net 3 08-27-2008 10:10 PM
How memory function free() knows how much memory to free. Panduranga Chary C Programming 2 12-27-2007 06:01 AM
use of MySQLConnection.dispose and/or MySQLCommand.dispose Antonio Concepcion ASP .Net 3 02-17-2005 06:33 PM



Advertisments