I'm having an out of memory error. I have a large range of inputs (2^40), that is too large to hold at once. Each input is a String[]
.
Instead, I thought I'd run my test program on each input, write the results to a file, then discard the input. The length
of the longest input is 42, so that isn't an error causing the overflow. I don't think I understand garbage collection.
PowerSet
is like a lazy list - the result isn't calculated until .next()
is called. Each result returns one subset of baseSet
.
baseSet
is a String[] with length 40.
runTests
does some analysis on the input and writes it to a file.
PowerSet argSetSet = powerset(baseSet);
while (argSetSet.hasNext()) {
runTests(argSetSet.next()); //saves output to file
}
This causes an out of memory error. But I'm not saving the result of argSetSet.next() anywhere, so why should this occur? I don't need to store any data from next()
or runTests()
. How can I make sure it's all being garbage collected?
If I comment out runTests()
, it runs fine.