Shutting Down


If you’re using an older compiler, then strange things can happen when your program exits. The newer compilers don’t seem to suffer from this problem, but I know that in the late 1990s, when you would create a new object and then let the object run out of scope at the end of your program, you had no guarantee that the object’s destructor would get called. Here’s the situation I’m talking about:

 int main() {      MyClass inst();  } 

A simple program like this in the past had no guarantee that the inst instance’s destructor would actually get called. However, I did test this out on three compilers—gcc, Microsoft Visual C++ 6.0, and Microsoft Visual C++.NET—and all was fine. The destructors do get called when an automatic instance inside main goes out of scope.

That aside, I won’t lecture you on the importance of cleaning up after yourself. Remember when your program closes to:

  • Close database connections.

  • Close any files you left open.

  • Delete any temporary files you left around.

  • Free any memory you allocated (don’t rely on the operating system to free the memory, even though it probably will).

You know the routine. From a GUI perspective, in addition, you’ll want to make sure you don’t just close the program without saving important information (such as the file your user was working on). All this should go without saying. Enough said.




Designing Highly Useable Software
Designing Highly Useable Software
ISBN: 0782143016
EAN: 2147483647
Year: 2003
Pages: 114

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net