Re: C# and destructors
From: Dmitriy Lapshin [C# / .NET MVP] (x-code_at_no-spam-please.hotpop.com)
Date: 04/23/04
- Next message: Ignacio Machin \( .NET/ C# MVP \): "Re: Collections of Collections in C#"
- Previous message: Dmitriy Lapshin [C# / .NET MVP]: "Re: Authentication of a user (single sign-on)"
- In reply to: Kimmo Laine: "C# and destructors"
- Next in thread: Jon Skeet [C# MVP]: "Re: C# and destructors"
- Reply: Jon Skeet [C# MVP]: "Re: C# and destructors"
- Reply: Kimmo Laine: "Re: C# and destructors"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 23 Apr 2004 16:39:43 +0300
Hi,
Please refer to the MSDN library on implementing the IDisposable interface
in components and the related design pattern.
-- Dmitriy Lapshin [C# / .NET MVP] X-Unity Test Studio http://www.x-unity.net/teststudio.aspx Bring the power of unit testing to VS .NET IDE "Kimmo Laine" <reply.to@newsgroup> wrote in message news:uktvoZTKEHA.3472@TK2MSFTNGP09.phx.gbl... > Hi, > > lets say that i have class (C#) which will create some kind of communication > chanel, which is very expensive in terms of computer resources, and > therefore should be closed, when no longer needed. I have a method which > will create this chanel and a method which will close/release it. > > My question is: is there a place where i can release this chanel if user > donīt call my release method? Can i write something like this: > > public class MyClass { > // My communication chanel > private TheChannel m_Channel; > > public MyClass() { > m_Channel = null; > } > > ~MyClass() { > if( m_Channel != null ) { > // Release channel > } > } > > public void CreateChannel() { //... } > public void CloseChannel() { //... } > } > > This method seems to work! But documentation says that "C# has no > destructor." It also says that is should use Dispose-method, like all the > .NET classes do, but it doesn't work! > > > Kimmo Laine > >
- Next message: Ignacio Machin \( .NET/ C# MVP \): "Re: Collections of Collections in C#"
- Previous message: Dmitriy Lapshin [C# / .NET MVP]: "Re: Authentication of a user (single sign-on)"
- In reply to: Kimmo Laine: "C# and destructors"
- Next in thread: Jon Skeet [C# MVP]: "Re: C# and destructors"
- Reply: Jon Skeet [C# MVP]: "Re: C# and destructors"
- Reply: Kimmo Laine: "Re: C# and destructors"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|