PC Review


Reply
Thread Tools Rate Thread

Dispose variables to free memory

 
 
Big George
Guest
Posts: n/a
 
      6th Sep 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
 
      7th Sep 2010
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.
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 Microsoft ASP .NET 3 27th Aug 2008 11:10 PM
How to free komputer memory after dispose Robert Microsoft C# .NET 5 10th Feb 2005 07:43 PM
Uninitialized variables in C# and Dispose() =?Utf-8?B?SmFrb2IgQmVuZ3Rzc29u?= Microsoft Dot NET 4 30th Jan 2004 12:18 PM
free up memory by deleting variables clui Microsoft Excel Programming 4 11th Dec 2003 01:10 AM
Dispose doesn't free memory Memory Issues Microsoft C# .NET 6 11th Nov 2003 10:44 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:56 PM.