A sudden freeze in an application can in some cases be a rather cumbersome problem to solve. Many times we don't have any indications why the application freezes no matter if is a Java, C# or C++ application, web site or dll. In some cases we might have a log file to help us look for the source of the hang or freeze, but in many cases we don't have any indications of problem until we suddenly run in Release mode and far from our dev env!
Here I will try to give some guidelines on how to attack this problem. Before you start diving into your code, fumbling in the dark, please consider the following:
- Is your application freeze followed by CPU-usage? If the process uses minimal resources (no cpu) during the lock, it's indicating that it could be a deadlock, resource lock situation etc.
- Is your application gradually eating more and more memory? In such case it indicates that it could be related to logical failure, eg. a "broken" Do-While or similar
- Is there a high CPU usage on more than one core? Most likely indicating several of your threads running wild.
- Is your application multithreaded? Look for logical breaks resulting in deadlocks in your code around all wait, lock, Mutex etc.
With these questions answered there is not much else to do than dive into your code. Based on what you answered in the questions above look into the following pitfalls:
- Try to get a full overview of all threads that are started in your application
- TPC-client/server communication ending. Are you handling these correctly?
- Go through all your Do-While and verify that there are no pitfalls, and no special cases where you might end up with a situation where it never escapes the loop (Unless it is supposed to run "forever")
- Go through a Mutex situations. Verify that you use the correct Mutex names, that you allways release the Mutex in the finally block not at the end of the try-block (to avoid that a Mutex is held forever due to an exception)
- Go through all lock-statements and verify that they will not create deadlock situations
I think this will be a good start of debugging these freeze, application hang and deadlock situations. In case you have any other good tips, please feel free to add them in a comment on this post!