Click here to Skip to main content
15,886,035 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Frameworks prior to .Net 4.5 often couldn't do dispose because there was only protected Dispose and no public.

I remember that there was a method to delete these objects by manually accessing the objects in the system after going through two steps so that they could be deleted manually.

I can't find the code I used in the past, and it doesn't come out even when I search for it, so I ask a question.

If you remember, please give me a message.

What I have tried:

Found it on Google for over 5 hours.

I used a lot of keywords.

But I can't find it.

The last time I found it was two years ago.
Posted
Updated 16-Nov-20 5:47am

 
Share this answer
 
Comments
Eavan Kim 14-Nov-20 10:05am    
This can be seen by dispose of tcpclient in .net framework 4.0.

There was a bug where it was impossible to dispose, and I remember seeing that this was forcibly deleted under some namespace, and I used it once.

Since it was an incorrect method, I used it urgently at the time and did not write it down.

When I try to find it again, the search doesn't come out anymore, so I just hope that someone knows.
OriginalGriff 14-Nov-20 10:18am    
Are you sure? The Reference Source shows nothing unusual in the TCPClient.Dispose method:

https://referencesource.microsoft.com/#system/net/System/Net/Sockets/TCPClient.cs
Eavan Kim 14-Nov-20 10:40am    
https://drive.google.com/file/d/1Zi_xmXcv0LoABFM6qYetA5T7WgrN7ViI/view?usp=sharing

this thing.
You can seeing CS0122.

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs0122
OriginalGriff 14-Nov-20 11:26am    
You can't call the version with a bool parameter directly, as it is protected - but you can call the non-parameter version, which calls the bool version and passes true.

To call the parameterised version is pretty simple though: derive a class from the one you want to dispose and write a public MyDispose which calls the protected Dispose version. Then use that instead of the original class.
Eavan Kim 14-Nov-20 11:33am    
The important thing is that you cannot call Dispose.
Next, you need to know how someone can delete the object.
I need knowledge.
System functions are available and secure.
I used it
Can't find any more.
I know that's the'disposal' function the right way.
But if you used Idisposable, you know that you are calling object = null.
just i need GC's internal functions.
not GC.
I think I know what you mean...
I've ran into some classes with a private/protected Dispose method, but that did implement IDisposable, like the TcpClient you mention.
In these cases you have two options, cast to IDisposable and call Dispose or, the often intended method, call an alternative method, usually Close, instead.
This is probably by design and not a bug.
Probably because it makes more sense to "close" a connection than to dispose it.
I see that as far as the TcpClient goes, Dispose is accessible in .NET 4.7.2, but not 4 and 4.5 (and probably any older versions).

Another method of properly disposing these objects is by wrapping them in a using block, which still works.
C#
var client = new TcpClient();
client.Dispose(); // Error in .NET 4.5 and ealier
client.Close(); // This works and calls Dispose() internally

using (var client2 = new TcpClient())
{
    // Use client2 here, it is automatically disposed when it goes out of scope.
    // Works even in .NET 4.5 and earlier.
}
 
Share this answer
 
v3
TcpClient (i.e. "Sockets") originated circa 1983. At that time, there was no .NET and no IDisposable.

You used Close() then, and you use Close() now to close the connections and FREE resources.

TCP connections are typically "long-term" (minutes and hours and days). You maintain a long-term collection or reference. The times you can actually employ a "dispose / using" pattern in a "real situation" are slim to none.

Exposing .Dispose() is mostly redundant in the presence of .Close().
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900