My Java code contains a method (getPermutations) whose processing takes a huge amount of memory ( Complexity O(n!) ) and thus may throw an OutOfMemoryError. The important piece of code is this:
ArrayList<ArrayList<Station>> permutations = getPermutations(stations);
I do NOT want to increase the heap memory size on my particular machine, I can't change it on other ones either. What I am looking for is some sort of exception handling for this error (I am well aware that errors or throwables in general are not supposed to be caught).
So I want to react on an OutOfMemoryError with an adequate (graphical) message and prevent my tiny little program from crashing.
Is a SwingWorker the right way to go, how should it be used or are there better suiting alternatives?
Thanks in advance :-)