473,395 Members | 1,745 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,395 software developers and data experts.

garabe collection method

Ben
Could someone please verify if what I am doing as follow is corrected:

1. when dealing with custom class objects:
.....
public myObject as myClass
myObject as New myClass
.......here I am going to fill up myObject with info....tons of them
myObject = nothing
System.GC.Collect()

Is this correct? I don't want to directly include System.GC.Collect() into
myClass terminate sub because there are soooo many local variables to mark
for delete. So will this works or there is another better way?

2. When working with form class, where my form class is named "myForm"
myForm.DefInstance = nothing
System.GC.Collect()

or should I replace those two lines with:
MainMenu.DefInstance.Dispose(True)

Which one garantee that data will be deleted from machine memory?

Thanks.
Nov 21 '05 #1
5 875
In article <74**********************************@microsoft.co m>, Ben wrote:
Could someone please verify if what I am doing as follow is corrected:

1. when dealing with custom class objects:
....
public myObject as myClass
myObject as New myClass
......here I am going to fill up myObject with info....tons of them
myObject = nothing
System.GC.Collect()

Is this correct? I don't want to directly include System.GC.Collect() into
myClass terminate sub because there are soooo many local variables to mark
for delete. So will this works or there is another better way?


In the general case, I would say no that is not correct. There are
situations where explict calls to the GC can be benificial. But, for
the most part it should be avoided. Let the garbage collector do it's
job.

Now there are instances were you may have classes that use OS handles or
resources that need to be cleaned up explicitly. These are the
"unmanaged" resources you may hear about. Here is one link to an
article that talks a little more about Dispose and it's use:

http://msdn.microsoft.com/library/de...posemethod.asp

HTH
--
Tom Shelton [MVP]
Nov 21 '05 #2
If you run a tight loop creating and processing lots of objects you might
need to help GC by calling Dispose on removed objects.
But before doing so, profile your app and look at objects which survive GC
cycles.

By itself GC.Collect might not help at all.

HTH
Alex

"Ben" <Be*@discussions.microsoft.com> wrote in message
news:74**********************************@microsof t.com...
Could someone please verify if what I am doing as follow is corrected:

1. when dealing with custom class objects:
....
public myObject as myClass
myObject as New myClass
......here I am going to fill up myObject with info....tons of them
myObject = nothing
System.GC.Collect()

Is this correct? I don't want to directly include System.GC.Collect() into myClass terminate sub because there are soooo many local variables to mark
for delete. So will this works or there is another better way?

2. When working with form class, where my form class is named "myForm"
myForm.DefInstance = nothing
System.GC.Collect()

or should I replace those two lines with:
MainMenu.DefInstance.Dispose(True)

Which one garantee that data will be deleted from machine memory?

Thanks.

Nov 21 '05 #3
Ben
just curious, so when I do:

me.close()
does that automatically invoke dispose method or I would still need to call:
me.dispose(true)
when closing my form?

thanks.
"Tom Shelton" wrote:
In article <74**********************************@microsoft.co m>, Ben wrote:
Could someone please verify if what I am doing as follow is corrected:

1. when dealing with custom class objects:
....
public myObject as myClass
myObject as New myClass
......here I am going to fill up myObject with info....tons of them
myObject = nothing
System.GC.Collect()

Is this correct? I don't want to directly include System.GC.Collect() into
myClass terminate sub because there are soooo many local variables to mark
for delete. So will this works or there is another better way?


In the general case, I would say no that is not correct. There are
situations where explict calls to the GC can be benificial. But, for
the most part it should be avoided. Let the garbage collector do it's
job.

Now there are instances were you may have classes that use OS handles or
resources that need to be cleaned up explicitly. These are the
"unmanaged" resources you may hear about. Here is one link to an
article that talks a little more about Dispose and it's use:

http://msdn.microsoft.com/library/de...posemethod.asp

HTH
--
Tom Shelton [MVP]

Nov 21 '05 #4
On 2005-07-27, Ben <Be*@discussions.microsoft.com> wrote:
just curious, so when I do:

me.close()
does that automatically invoke dispose method or I would still need to call:
me.dispose(true)
when closing my form?


Me.Close should be sufficient.

--
Tom Shelton [MVP]
Nov 21 '05 #5
That depends on how the form was shown in the first place. If you
showed the form using ShowDialog, then you need to call Dispose. If
you showed using just Show, then Dispose is called automatically.

Nov 21 '05 #6

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

Similar topics

8
by: Generic Usenet Account | last post by:
To settle the dispute regarding what happens when an "erase" method is invoked on an STL container (i.e. whether the element is merely removed from the container or whether it also gets deleted in...
7
by: Pete Davis | last post by:
A different question this time. I have a DataGrid bound to a collection. Is there any way for me to allow sorting? The DataGrid.AllowSorting=true doesn't work, but that's probably because it can't...
2
by: Edward Diener | last post by:
In C++ an overridden virtual function in a derived class must have the exact same signature of the function which is overridden in the base class, except for the return type which may return a...
2
by: Brian | last post by:
NOTE ALSO POSTED IN microsoft.public.dotnet.framework.aspnet.buildingcontrols I have solved most of my Server Control Collection property issues. I wrote an HTML page that describes all of the...
16
by: Ben Hannon | last post by:
Hi, I'm writting a COM Class in VB.NET to be used in a VB6 project (Tired of the VB6 hassles with cloning and serializing an object). All my classes I need cloneable/serializable are now in a...
2
by: Ian Gore | last post by:
Hi, I'm relatively new to VB.NET so I'd be grateful if someone could point out what I don't understand here... 1) Creating a strongly typed collection by inheriting CollectionBase. This is...
1
by: m. pollack | last post by:
Hi all, I'm still trying to get to the bottom of the problem I am having with the CollectionBase class and the Object Collection Editor. Briefly put, I am exposing a strongly-typed collection...
1
by: Dale Levesque | last post by:
Does anybody know how to determine if a collection contains a specific member but not by key value as performed by the contains method? I have a collection of custom structures that I only want to...
8
by: Tanzen | last post by:
I'm working in visual studio 2005 trying to learn visual basic. Having come from an VB for Access background, I'm finding it a big learning curve. I have been working through several e-books which...
10
by: Andy B | last post by:
Is it safe to make a method that returns a match collection or nothing? or is it better to just return a match collection and have the code outside the method validate that match collection is...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.