This is a wrong approach. If you have threads stuck because they are waiting for each other forever, this is a problem called
deadlock. It can be much more serious than your memory leaks. You should not aim to "release" them; you should prevent them. Please see:
http://en.wikipedia.org/wiki/Deadlock[
^].
You can achieve this goal through accurate architecture and design of your system. One interesting and simple method of threaded system analysis is using the
Petri net formalism. Please see:
http://en.wikipedia.org/wiki/Petri_net[
^].
This excellent Microsoft article teaches us how to use it in practice:
http://msdn.microsoft.com/en-us/library/ms810303.aspx[
^].
Now, let's come back to memory leaks. Nothing in your question tells me that you have detected the real reasons for your memory leaks. You should approach this problem from accurate diagnostics. You can use some development tool from the class of tools called "
memory debugger". Please check the list of available memory debuggers found in this article:
http://en.wikipedia.org/wiki/Memory_debugger[
^].
Good luck,
—SA