I have a ref sealed abstract class (.NET) that all its members are static and it has a static constructor. I wnat to do something at the end of my work with the class, can I have a destructor in some way?
I have a ref sealed abstract class (.NET) that all its members are static and it has a static constructor. I wnat to do something at the end of my work with the class, can I have a destructor in some way?
Learn C++ (C++ Books, C Books, FAQ, Forum Search)
Code painter latest version on sourceforge DOWNLOAD NOW!
Download FSB Data Integrity Tester.
Siavosh K C
No, sealed abstract classes cannot have destructors. Since it's both sealed and abstract (or, in C# terms, static), you cannot create an instance of the class. Because you don't have an instance, you'd never run the destructor either. The class will finally go away once the application domain is unloaded. At that point, what could you really want to do?
On a semi-related note, static events can cause big problems for the garbage collector if you don't unsubscribe from them. Since static events don't go away until the application domain is unloaded and events contain a reference to every object that is subcribed to them, if you don't unsubscribe from them before releasing all references to an object, then at best you'll just have a chunk of unusable memory. At worst, you'll have an object still responding to events that you didn't expect.
If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein
So I added a method that should be called when we finished with that calss.No, sealed abstract classes cannot have destructors.
Learn C++ (C++ Books, C Books, FAQ, Forum Search)
Code painter latest version on sourceforge DOWNLOAD NOW!
Download FSB Data Integrity Tester.
Siavosh K C
This isn't the rigth forum to ask about .Net implementations of C++.
Originally Posted by brewbuck:
Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.
On a semi-related note, static events can cause big problems for the garbage collector if you don't unsubscribe from them. Since static events don't go away until the application domain is unloaded and events contain a reference to every object that is subcribed to them, if you don't unsubscribe from them before releasing all references to an object, then at best you'll just have a chunk of unusable memory. At worst, you'll have an object still responding to events that you didn't expect.
So if we have
Object ^ obj = gcnew Object;
Should be enough for GC right?Code:obj = nullptr;
Last edited by siavoshkc; 09-07-2006 at 05:07 PM.
Learn C++ (C++ Books, C Books, FAQ, Forum Search)
Code painter latest version on sourceforge DOWNLOAD NOW!
Download FSB Data Integrity Tester.
Siavosh K C
That's enough for that reference. Objects are only collected if all references to them are released. Since events keep a reference to each object that's subscribed to them, just setting all of your explicit references to nullptr isn't enough; you also have to unsubscribe from every event whose lifetime is longer than that of your object. Since static events are around until the application domain is unloaded, that basically means that your objects will be around until the application closes unless you unsubscribe from them.Originally Posted by siavoshkc
If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein
OK, I'll keep that in mind, thanks.
Learn C++ (C++ Books, C Books, FAQ, Forum Search)
Code painter latest version on sourceforge DOWNLOAD NOW!
Download FSB Data Integrity Tester.
Siavosh K C