K
Kimmo Laine
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
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