473,382 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

When to call dispose()?

Hi,
I have a form containing controls, a timer, and the EventLog component.
I also create some new instances of classes that do not implement idisposable
I don't want to leave the tidying up to the GC so...
Do I need to explicitly call EventLog.dispose() as in the following snippet?

protected overloads sub dispose(byval disposing as boolean)
if disposing
if components is nothing then
components.dispose
end if
call MyEventLog.dispose(True) <<<--
end if
end sub

Also how do I make sure that the classes that don't implement idisposable return their memory one I've finished.Do I just close them, or set them to nothing, or what?

Help much appreciated
Jul 21 '05 #1
2 3455
Cor
Hi Nigel,

My idea is that if not is strictly written in the documentation that
something has to be disposed (by instance large bitmaps) not to do it.

It cannot be else than that a dispose takes some action, so let it be done
in one cleansweep at the end.

My idea about it is the same as closing a book, what I opens a lot of times
again and dispose when I never read it again.

Cor
I have a form containing controls, a timer, and the EventLog component.
I also create some new instances of classes that do not implement idisposable I don't want to leave the tidying up to the GC so...
Do I need to explicitly call EventLog.dispose() as in the following snippet?
protected overloads sub dispose(byval disposing as boolean)
if disposing
if components is nothing then
components.dispose
end if
call MyEventLog.dispose(True) <<<--
end if
end sub

Also how do I make sure that the classes that don't implement idisposable

return their memory one I've finished.Do I just close them, or set them to
nothing, or what?
Jul 21 '05 #2

Nigel why dont you want to leave memory reclaimation to the GC? The purpose of IDisposable is to A: allow you to dispose in a neat fashion, and B: to indicate to the class consumer that the class has resources that should be released at the earliest convenience - such as file handles, DB connections etc. In all other cases it is best to leave the memory to the GC. Even if IDisposable.Dispose is invoked, the object itself is still left to GC collection at some other time. Also look at overriding Finalize. To instigate a memory collection, call GC.Collect();

Nick.

----- Nigel T wrote: -----

Hi,
I have a form containing controls, a timer, and the EventLog component.
I also create some new instances of classes that do not implement idisposable
I don't want to leave the tidying up to the GC so...
Do I need to explicitly call EventLog.dispose() as in the following snippet?

protected overloads sub dispose(byval disposing as boolean)
if disposing
if components is nothing then
components.dispose
end if
call MyEventLog.dispose(True) <<<--
end if
end sub

Also how do I make sure that the classes that don't implement idisposable return their memory one I've finished.Do I just close them, or set them to nothing, or what?

Help much appreciated
Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Cybertof | last post by:
Hi ! I'm wondering about the use of the 'using' statement. In a procedure, should i declare all instance variables in a using clause ? In the below code, what would happen if MyFont & MyFont2...
4
by: Terry | last post by:
There are a number of things about using unmanaged resources in Windows Forms programming that is unclear to me. In C++, if you loaded an icon resource using "ExtractIcon()", the resource was...
1
by: Rhy Mednick | last post by:
I'm creating a custom control (inherited from UserControl) that is displayed by other controls on the form. I would like for the control to disappear when the user clicks outside my control the...
2
by: Jaikumar | last post by:
Hi, 1) I have created one windows application, In the main form ( form1) i have added one usercontrol (usercontrol1), In that user control i am drawing one image. 2) In the UserControl1 i am...
9
by: Razzie | last post by:
Hey all, When should or should you not inherit from the IDisposable interface for your custom classes? Say I have a custom class SomeClass that does... some stuff. If I create a new instance...
20
by: Charles Law | last post by:
I have an application that creates a class. The class has unmanaged resources, so must end gracefully. How can I guarantee that the unmanaged resources are freed? I have looked at IDisposable,...
21
by: StriderBob | last post by:
Situation : FormX is mdi child form containing 2 ListViews ListView1 contains a list of table names and 4 sub items with data about each table. ListView2 contains a list of the columns on each...
46
by: clintonG | last post by:
Documentation tells me how but not when, why or where... <%= Clinton Gallagher http://msdn2.microsoft.com/en-us/library/saxz13w4(VS.80).aspx
11
by: MikeT | last post by:
This may sound very elementary, but can you trap when your object is set to null within the object? I have created a class that registers an event from an object passed in the constructor. When...
44
by: Smokey Grindle | last post by:
I have a list box on my form, but I need to databind it to a data table that is a private member of the form's class... so I basically have Public Class MyForm priate m_MyTable as new datatable...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.