473,789 Members | 2,496 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MVP's Please respond!

Hi All, To my correct understanding Garbage Collection works based on
Generation algorithm...(hi gh level).
I have an application which does some heavy operations usually File I/O's. I
want to force garbage collection on this class. I still want the GC to
release all resources before finalizing etc...but I want GC to kick in ASAP,
rather waiting to execute its algo to detect that this class needs cleaning
up and finally come to its rescue...

This is what I have implemented. Please advice

TIA

class Foo:IDisposable
{

public void Dispose()
{
GC.Collect();
}

}
Nov 16 '05 #1
2 1204
Hi Vai2000 ,

Take a look at System.GC class. It has methods:
GC.Collect() to force grabage collection
GC.WaitForPandi ngFinalizers() - after calling GC.Collect it will block until
all finalizers finish.

--
HTH
Stoitcho Goutsev (100) [C# MVP]
"Vai2000" <no****@microso ft.com> wrote in message
news:OQ******** ******@TK2MSFTN GP12.phx.gbl...
Hi All, To my correct understanding Garbage Collection works based on
Generation algorithm...(hi gh level).
I have an application which does some heavy operations usually File I/O's. I want to force garbage collection on this class. I still want the GC to
release all resources before finalizing etc...but I want GC to kick in ASAP, rather waiting to execute its algo to detect that this class needs cleaning up and finally come to its rescue...

This is what I have implemented. Please advice

TIA

class Foo:IDisposable
{

public void Dispose()
{
GC.Collect();
}

}

Nov 16 '05 #2
[For future reference - it would be better to give a subject line which
actually describes your problem. You may also have alienated others who
have a perfectly good answer but aren't MVPs.]

Vai2000 <no****@microso ft.com> wrote:
Hi All, To my correct understanding Garbage Collection works based on
Generation algorithm...(hi gh level).
I have an application which does some heavy operations usually File I/O's. I
want to force garbage collection on this class. I still want the GC to
release all resources before finalizing etc...but I want GC to kick in ASAP,
rather waiting to execute its algo to detect that this class needs cleaning
up and finally come to its rescue...

This is what I have implemented. Please advice

class Foo:IDisposable
{
public void Dispose()
{
GC.Collect();
}
}


That looks like a very bad idea to me. Why do you think it's a good
idea to force garbage collection? Much better would be to call Dispose
on all the appropriate streams explicitly. That will release the
unmanaged resources but not force a potentially expensive garbage
collection.

--
Jon Skeet - <sk***@pobox.co m>
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

16
3965
by: Thomas G. Marshall | last post by:
This message is sent to these newsgroups because they are no longer valid: comp.lang.java comp.lang.java.api comp.lang.java.bugs comp.lang.java.misc comp.lang.java.setup comp.lang.java.tech
0
1115
by: eric cocozza | last post by:
Hi, I just moved a python program to a new server, and I'm getting path errors. It relys on the pear library and a image processing one. Please respond with cost based on 1/hr of work, and please accept paypal, or other simple form of payment. Thanks!
26
2944
by: Michael Strorm | last post by:
Hi! I posted a message a while back asking for project suggestions, and decided to go with the idea of creating an adventure game (although it was never intended to be a 'proper' game, rather an excuse to write- and learn- some C++). To cut a long story short, I wrote a fair chunk of it, but realised that it's... not very good. Okay, it's my first "proper" C++ program, so that's no big deal, but I don't want to waste more time working...
2
1083
by: Amit D.Shinde | last post by:
I can see many MVP answers my doubts..Thanks to all Members of Newsgroup Can any one of you tell me what's MVP and what are its requirements? How to register to become a MVP
3
1364
by: Ron | last post by:
How to handle this when using custom membership provider. Please refer to my first question which is posted. "Custom Membership Provider" Thanks, Ron
18
2211
by: Chris Hills | last post by:
A lesson in Posting How many C.L.C group posters does it take to change a C light bulb? 1 to change the light bulb and to post that the light bulb has been changed 14 to share similar experiences of changing light bulbs and how the light bulb could have been changed differently
31
1686
by: Simply_Red | last post by:
i'm sorry i posted this in other groupes, and i didn't see it, and as this group is most actif, i repost it here, and sorry for mutliposting: Hi, i'm using VC6, i have this declaration: typedef struct tagTLimite { double Debut; double Fin;
12
1516
by: Zilla | last post by:
I put everything in one file for ease of use; also I have #include <*.hfiles instead of the <*since my compiler is pre-ANSI C so it needs the .h #include <iostream.h> #include <iomanip.h> #include <string.h> class Cmd { public:
2
5569
by: blogman | last post by:
I am getting a Visual studio 2008 IDE application R6034 runtime error. This means that the IDE application is raising the error not the application I am building. This means that Microsoft did not follow its own advice as listed in http://msdn.microsoft.com/en-us/library/ms235560(VS.80).aspx and "build with a manifest". The DLL in question seems to be msvcr8.0.dll which is the VS2005 C runtime DLL. I am not sure why this is an issue in a...
0
9506
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10193
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9979
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9016
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7525
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6761
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5415
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.