title: Identifying point when StackOverFlow Error happen
body: <p>I am writing an educational program for students, where they can see how different algorithms work when solving Traveling salesman problem (Time consumption, visual representation of state etc.). The problem is that not only I have to show good algorithms but I have to show bad ones as well. For instance I implement Breadth-first search algorithm for TSP (horrible choice). </p>
  
  <p>Program itself is written in Java. I have a seperate thread for problem solver algorithm and all algorithms implement a specific interface which allows me to interfere after each iteration. </p>
  
  <p>All blind-search algoritms which run over a tree structure with N nodes (n= number of cities) and each node is an array of N elements, that implementation produces a StackOverFlow Exception after around generating ~ 50k nodes. I dont want to limit user interface so that limited ammount of cities can be used- simulated anneal works with thousands of cities. </p>
  
  <p>Here is the question: 
  Is there some reliable function I could use in some specified logical statement so that I could identify the point when System is about to crash? 
  Something is style : if (System.memoryLeft() &lt;= 100 /<em>bytes</em>/ ) { // Stop working and take action</p>
  
  <p>Thanks in advance. </p>