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

Will the GC clean this up?

Newbie C# developer question:

class myStuff
{
private System.Object o;

public void doWork()
{
o = new Sytem.Object;
}
}

Will the GC take care of cleaning up the resource myStuff.o is using when
the myStuff object goes out of scope?

Craig
Nov 16 '05 #1
6 1003
Yes, so long as the resources that myStuff.o is holding internally are
_managed_. myStuff.o itself will certainly be cleaned up when myStuff
goes out of scope.

The only things that wouldn't be cleaned up would be any pointers to
unmanaged resources, usually gained via calls to non-.NET dlls or the
Windows API, that myStuff.o may be holding. If you have those sorts of
resources, you must be sure to release them via a try...finally, a
using, or a Dispose() method.

As well, there seem to be some managed types that benefit from explicit
disposal. The ones I've run across are Forms and Images, but there may
be other. This seems to speed up the GC process.

Nov 16 '05 #2
Maybe not when it goes out-of-scope, but the GC will mark it for deletion
and will delete it when the GC feels it's the best time to do so.
"Craig" <WeeksAtSprynetDotCom> wrote in message
news:Oj**************@TK2MSFTNGP12.phx.gbl...
Newbie C# developer question:

class myStuff
{
private System.Object o;

public void doWork()
{
o = new Sytem.Object;
}
}

Will the GC take care of cleaning up the resource myStuff.o is using when
the myStuff object goes out of scope?

Craig

Nov 16 '05 #3
ASAIK, the GC will clean up all managed objects that are no longer
referenced.
"Craig" <WeeksAtSprynetDotCom> wrote in message
news:Oj**************@TK2MSFTNGP12.phx.gbl...
Newbie C# developer question:

class myStuff
{
private System.Object o;

public void doWork()
{
o = new Sytem.Object;
}
}

Will the GC take care of cleaning up the resource myStuff.o is using when
the myStuff object goes out of scope?

Craig

Nov 16 '05 #4
DataTables also really like to be disposed.
"Bruce Wood" <br*******@canada.com> wrote in message
news:11*********************@l41g2000cwc.googlegro ups.com...
Yes, so long as the resources that myStuff.o is holding internally are
_managed_. myStuff.o itself will certainly be cleaned up when myStuff
goes out of scope.

The only things that wouldn't be cleaned up would be any pointers to
unmanaged resources, usually gained via calls to non-.NET dlls or the
Windows API, that myStuff.o may be holding. If you have those sorts of
resources, you must be sure to release them via a try...finally, a
using, or a Dispose() method.

As well, there seem to be some managed types that benefit from explicit
disposal. The ones I've run across are Forms and Images, but there may
be other. This seems to speed up the GC process.

Nov 16 '05 #5
Uchiha Jax <i_************************@NOSPAMhotmail.com> wrote:
DataTables also really like to be disposed.


I've heard this before, but with no actual evidence. Could you give an
example? I don't think calling Dispose on a DataTable does anything
interesting unless it's in a container.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6

I don't see why you'd say a DataTable wants to be disposed, especially
since DataTables always suppress finalization (it's in the default
constructor) which means that Dispose will not be called unless you
call it yourself (implying it doesn't need to be called at all).

DataTable also doesn't implement Dispose itself at all--the only
implementation it has is what it receives from
MarshalByValueComponent, which removes it from the container if one
exists and broadcasts the disposed event. Besides this, as far as I
can tell a DataTable never beomes sited unless you specifically set
the Site property.

Sam
On Wed, 02 Mar 2005 19:25:52 GMT, "Uchiha Jax"
<i_************************@NOSPAMhotmail.com> wrote:
DataTables also really like to be disposed.
"Bruce Wood" <br*******@canada.com> wrote in message
news:11*********************@l41g2000cwc.googlegr oups.com...
Yes, so long as the resources that myStuff.o is holding internally are
_managed_. myStuff.o itself will certainly be cleaned up when myStuff
goes out of scope.

The only things that wouldn't be cleaned up would be any pointers to
unmanaged resources, usually gained via calls to non-.NET dlls or the
Windows API, that myStuff.o may be holding. If you have those sorts of
resources, you must be sure to release them via a try...finally, a
using, or a Dispose() method.

As well, there seem to be some managed types that benefit from explicit
disposal. The ones I've run across are Forms and Images, but there may
be other. This seems to speed up the GC process.


B-Line is now hiring one Washington D.C. area VB.NET
developer for WinForms + WebServices position.
Seaking mid to senior level developer. For
information or to apply e-mail resume to
sam_blinex_com.
Nov 16 '05 #7

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

Similar topics

8
by: Craig Thomson | last post by:
I was wondering what people do with text provided by the user in a form. Some cleaning needs to be done at some stage if you are going to be putting it in a database or displaying it etc. But when...
90
by: Mark Hahn | last post by:
"Michael Geary" <Mike@Geary.com> wrote ... >Does anyone have some sample code where obj$func() would be used? > (Apologies if I missed it.) There have been so many messages about delegation...
5
by: Rob R. Ainscough | last post by:
I have a moderately sized web application (30 pages, and 20 DLLs) that takes 10-20 minutes to "Build Solution" after I do a "Clean Solution" -- this is ONLY apparent after a "Clean Solution" I...
0
by: Christopher | last post by:
How can I make a vc++ project erase its $(OutDir) upon using the clean command? I tryed Properties->Configuration Properties->General->Extensions to Delete on Clean Add $(ObjDir) And it...
10
by: Simon | last post by:
As title. How to clean out VSWebCache? Any good way to do that? Thanks.
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: 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...
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
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...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.