[Mono-devel-list] Patch that implements WaitForPendingFinalizers
Gonzalo Paniagua Javier
gonzalo at ximian.com
Thu Apr 17 10:15:00 EDT 2003
Hi there!
When running some xsp stuff, noticed that sometimes the DB connections
where not being closed... Then I tried WaitForPendingFinalizers to see
if there was any connection object pending finalization and realized
that it was an empty function.
I've attached a patch for gc.c that solves this issue. It also runs the
finalizers upon domain shutdown so that the finalizer in the attached
finalizers-simple.cs is run.
A sample output I got from finalizers.cs (I added a Console.WriteLine to
Socket.cs finalizer and enabled those g_print lines):
-------
Waiting
Done
Waiting
Waiting for pending finalizers....
Disposing socket
Disposing socket
Zzzzzz
Zzzzzz
Disposing socket
Zzzzzz
Done pending....
Done
Waiting
Done
-------
Ok to commit?
-Gonzalo
-------------- next part --------------
using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
class C
{
byte [] result;
byte [] Run ()
{
result = new byte [10000000];
result [0] = (byte) 'a';
Socket s = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
s.Connect (new IPEndPoint (IPAddress.Loopback, 21)); // ftp
return result;
}
~C ()
{
Console.WriteLine ("Zzzzzz");
}
static bool finished = false;
static void Other ()
{
for (int i = 0; i < 10; i++) {
C c = new C ();
c.Run ();
Thread.Sleep (2000);
}
finished = true;
}
static void Main ()
{
Thread th = new Thread (new ThreadStart (Other));
th.Start ();
while (!finished) {
Thread.Sleep (500);
Console.WriteLine ("Waiting");
GC.WaitForPendingFinalizers ();
Console.WriteLine ("Done");
}
}
}
-------------- next part --------------
using System;
using System.Threading;
class C
{
~C ()
{
Console.WriteLine ("Zzzzzz");
}
static void Main ()
{
new C ();
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gc.patch
Type: text/x-patch
Size: 1734 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20030417/48d4ef9f/attachment.bin
More information about the Mono-devel-list
mailing list