Steve Luke wrote:OUtOfMemoryError is an Error, not an Exception. Errors tend to be un-recoverable, so you generally don't catch them.
I see.
heres a screenshot of the dictionary that my program stores:
the insertion basically goes:
1. Seen a B? no, add to dictionary, output <0, B>
2. Seen a A? no, add to dictionary, output <0, A>
3. Seen a D? no, add to dictionary, output <0, D>
4. Seen a B? yes, add to String
word, move along
5. Seen a B followed by an A? no, add BA to dictionary output <1, A>
6. Seen a D? yes, add to String word, move along
7. Seen a D followed by a G? no, add DG to dictionary output <3, G>
and so on. So the dict just keeps growing as new words get added.
There must be something i can do as most publications about LZ78 state the 2 main ways to prevent the dictionary from growing forever are to a. limit the size of the dictionary or b. check to see if theres available memory to insert another item (in my case a node containing a String, an Integer and 2 pointers).
while a. is an obvious solution and easy to implement, it means when deciding on the MAXSIZE of the dictionary, I have to ensure that I select a size that caters to all memory sizes. There are so many people around still using Celerons with 256MB of memory that I would have to use that as a basis and declare a size that will fit into that.
but more elegant is a program that extends to the full capability of the system your working on - if your working on a quadcore with 4GB of memory or an Amstrad it wont matter - the program will still run ( granted it might take a few years to run on the Amstrad, but the point stands)
what i basically want in pseudocode is:
I see what your saying about memory leaks and while my program is far from robust, Thats not the reason i want to throw the exception. I want the dictionary to be a memory hog while its compressing so i get the best possible compression ratio and only throw away the dictionary when i dont have a choice.