473,405 Members | 2,176 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,405 software developers and data experts.

calling GC

Hi all
I want to know how can I force GC to be callled?

thanks in advance
Dec 21 '06 #1
6 1117
GC.Collect();

However, this is not recommended in most scenarios. Normally, just let
the GC do its thing. Do you have a specific reason for wanting to
force this? There may be better options...

Marc
Dec 21 '06 #2

Marc Gravell wrote:
GC.Collect();

However, this is not recommended in most scenarios. Normally, just let
the GC do its thing. Do you have a specific reason for wanting to
force this? There may be better options...

Marc
Also
GC.WaitForPendingFinalizers();

If you want a synchronous call to wait until all the finalizers are
complete (the collect method is launched in a separate thread)

--------------------------------------------------------------
visit: www.scogico.com

Dec 21 '06 #3
Hi Perspolis,
you can force the garbage collector to run by calling GC.Collect() which
will force a collection on all generations of eligable objects to be
collected. Generally though you should not have to force the GC since it
knows best when to run, what problem are you trying to solve?

Mark.
--
http://www.markdawson.org
"perspolis" wrote:
Hi all
I want to know how can I force GC to be callled?

thanks in advance
Dec 21 '06 #4
I have a database application and using pooling in my connection.
In some reasons I want to restore my database (SqlServer).
but because of pooling it give me error "The database is using ";
I have a method that clears SqlConnection pool and place it in destructore.
But when I want tor restore the destructor has no been called yet.

"Marc Gravell" <ma**********@gmail.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
GC.Collect();

However, this is not recommended in most scenarios. Normally, just let the
GC do its thing. Do you have a specific reason for wanting to force this?
There may be better options...

Marc


Dec 21 '06 #5
pedant note: finalizer, not destructor

If you want deterministic cleanup of some bespoke object (of yours),
then IDisposable is a much better pattern than a finalizer.
Theoretically you should just have to call ClearAllPools(), and then
ensure that all in-use connections are properly closed (and ideally
disposed). I haven't tried it though. Of course, since you obviously
have elevated privelege at the database (to invoke a restore), you
could also presumably kill the spids from the server.

http://msdn2.microsoft.com/en-us/lib...ca(VS.80).aspx

Marc
Dec 21 '06 #6
Good catch; in the (undesirable) scenario where you are dependent on a
particular finalizer, then sync rather than async is necessary. But
best to avoid it in the first place (IDisposable etc).

Marc
Dec 21 '06 #7

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

Similar topics

1
by: Asapi | last post by:
1. Are linkage convention and calling convention referring to the same thing? 2. Does calling convention differ between languages C and C++? 3. How does calling convention differ between...
8
by: Muthu | last post by:
I've read calling conventions to be the order(reverse or forward) in which the parameters are being read & understood by compilers. For ex. the following function. int Add(int p1, int p2, int...
7
by: Klaus Friese | last post by:
Hi, i'm currently working on a plugin for Adobe InDesign and i have some problems with that. I'm not really a c++ guru, maybe somebody here has an idea how to solve this. The plugin is...
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
3
by: Mike | last post by:
Timeout Calling Web Service I am calling a .NET 1.1 web service from an aspx page. The web service can take several minutes to complete its tasks before returning a message to the aspx page. ...
2
by: Geler | last post by:
A theoretical question: Sorry if its a beginner question. Here is a quote from the MSDN explaning the C/C++ calling convention.. It demonstrates that the calling function is responsible to clean...
47
by: teju | last post by:
hi, i am trying 2 merge 2 projects into one project.One project is using c language and the other one is using c++ code. both are working very fine independently.But now i need to merge both...
7
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file...
10
by: sulekhasweety | last post by:
Hi, the following is the definition for calling convention ,which I have seen in a text book, can anyone give a more detailed explanation in terms of ANSI - C "the requirements that a...
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: 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
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...
0
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...

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.