title: Calculating memory occupied by a ThreadGroup
body: <p>I am writing application that is capable of running multiple instances of a Java game. Each instance of the game has multiple threads, which are grouped in a <code>ThreadGroup</code> object. I want to be able to detect the fact that another instance of the game could not be added because there will probably not be enough memory. The way that I plan to implement this is by averaging the amount of memory occupied by each <code>ThreadGroup</code>, and then determining if there is enough space available in memory with the aid of <code>Runtime.getRuntime().freeMemory()</code>. However, I can't find a programmatic way of calculating the amount of memory that a <code>ThreadGroup</code> (or even an individual thread) occupies.</p>
  
  <p>I found profilers that are capable of displaying this information, but I need this solution to be programmatic.</p>