G
Guest
Async functionality prevents an object from garbage collection.
To reproduce:
Create a socket
establish connection
Create NetworkStream with Ownership Of a socket (or just work socket directly)
Call BeginReceive on stream or socket
dereference network stream
The conneciton will stay up until parent process is terminated.
What GC should be doing is releasing a handle of an underlying socket which
it does not.
pseudo code:
void init()
{
init socket
socket.connect()
init networkstream(owns the socket)
networkstream.beginread(async parameters)
}
void main()
{
for (int j = 0; j < 100; j++)
{
init();
}
GC.Collecti();
GC.WaitForPendingFinalizers();
break here (console read)
}
netstat will show 100 established connections that will never go away.
To reproduce:
Create a socket
establish connection
Create NetworkStream with Ownership Of a socket (or just work socket directly)
Call BeginReceive on stream or socket
dereference network stream
The conneciton will stay up until parent process is terminated.
What GC should be doing is releasing a handle of an underlying socket which
it does not.
pseudo code:
void init()
{
init socket
socket.connect()
init networkstream(owns the socket)
networkstream.beginread(async parameters)
}
void main()
{
for (int j = 0; j < 100; j++)
{
init();
}
GC.Collecti();
GC.WaitForPendingFinalizers();
break here (console read)
}
netstat will show 100 established connections that will never go away.