need to implement and call the necessary methods yourself anyway. So no, I don't really see any issue there.
In languages with RAII and "other" solutions to memory management (such as C++ or Objective-C), you indeed need to implement the specialized cleanup code (as you would in C# / Java) (such as send disconnect messages, stop thread etc...) however, you don't need to call the methods yourself. This is extremely important for me because if an exception has been thrown, then in many cases the manual calling of the cleanup code you would need to do in C#, would not be called.
// Pseudo-code/C#: The IDisposable pattern has too much boilerplate for me to be bothered.
MyThread mythread;
Constructor()
{
myThread = new MyThread();
// oops an exception is thrown
}
~Finalizer()
{
if(myThread != null) { myThread.Destroy(); }
}
void Dispose()
{
if(myThread != null) { myThread.Destroy(); }
}
The finalizer or Dispose function for a class that never completed its constructor will never be called. You now have a Memory / Resource leak
In C++, the thread started by start thread would be destroyed (as the thread object pops off the stack), however in C#, this is made even worse by the fact that the garbage collector will never cleanup the thread because even though it has no reference left, it still has a unit of execution running on it (i.e itself).
Again, this can be solved elegantly using either RAII in native C++ or auto_handle in managed C++/CLR
In C# or Java, the solution might be something like this (which I personally dont like)
Constructor()
{
try
{
myThread = new MyThread();
// oops an exception is thrown
}
catch(Exception)
{
Dispose();
throw;
}
}
Ironically when I use Java and C#, I find myself writing more cleanup code than C++ (which admittedly requires none unless you use low-level C libraries (as you would also need to in C#/Java).