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

Basics...

DC
Hi!

Is code like:

<code>
FormX f = new FormX();
f.ShowDialog();
f.Dispose();
GC.Collect();
</code>

bad thing or good thing?
Thanks,
Dejan
Nov 16 '05 #1
2 1064
DC wrote:
Is code like:

<code>
FormX f = new FormX();
f.ShowDialog();
f.Dispose();
GC.Collect();
</code>

bad thing or good thing?


it's useless I'd say. IMHO you only have to dispose of unmanaged
resources if you want to free memory. Disposing of a form which is not
in use anymore and out of scope is done automatically as soon as memory
is needed. f.Dispose() and GC.Collect() are therefore not needed unless
your form does some dirty things and overrides the Dispose() method of
the base class.

--
Konrad -
http://madrat.net/
Nov 16 '05 #2
Konrad L. M. Rudolph <ko************@madrat.net> wrote:
DC wrote:
Is code like:

<code>
FormX f = new FormX();
f.ShowDialog();
f.Dispose();
GC.Collect();
</code>

bad thing or good thing?


it's useless I'd say. IMHO you only have to dispose of unmanaged
resources if you want to free memory. Disposing of a form which is not
in use anymore and out of scope is done automatically as soon as memory
is needed. f.Dispose() and GC.Collect() are therefore not needed unless
your form does some dirty things and overrides the Dispose() method of
the base class.


Windows handles are not an infinite resource, and not one which the
garbage collector keeps track of. While I agree that the call to
GC.Collect() isn't needed, you should *always* make sure that classes
which implement IDisposable have their Dispose methods called. There's
more to unmanaged resources than just memory!

I would, however, change the format of the code to:

using (FormX f = new FormX())
{
f.ShowDialog();
}

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

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

Similar topics

1
by: enki | last post by:
I have been learning perl and C++, and I have been looking into Java. I know very little about the language, I have found some realy bad books that realy served to confues me and I have to find...
0
by: James Messick | last post by:
I'm just getting started with MySQL. Got my first db created and can run SQL against it in the phpAdmin program. Is there a tutorial online somewhere that shows me the basics of accessing it from a...
2
by: Kurien Baker Fenn | last post by:
I would like to show the progress of an application using the progress bar in visual basics using the timer.Please help me. Thanks in advance.
1
by: manish | last post by:
Hi, I am a fresher in the programming field i.e although I have done programming at the basic level but at professional level I am very new and I am facing many problems. These probllems are...
1
by: ThunderMusic | last post by:
Hi, I need to send some data from my app to a remote server. So, after some searches, I found the best way would be to use web services (unless you can suggest me other ways). The data sent will...
14
by: chitu | last post by:
Hi pals, Hope u all of r intersted in C programming.Let start from d basics.
5
by: Jyoti Khalap | last post by:
HI Can Anyone help me out with my problem its very urgent I want to import text file to my visual basics application because everytime its a new text file depending on that text file i want to...
3
Mague
by: Mague | last post by:
Hey, I need help to some how open a exe file with Microsoft Visual basics. You mite think im trying to steal someone elses project but im not i wont to no how they did it and upgrade it if...
0
by: babu8880 | last post by:
www.convensysglobal.com/elearn You can login and attend courses and similar resources ask your doubts from experienced engineers in iphone and Objective C Domain You can attend live classes...
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: 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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
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.