[MCOMB-2] OutOfMemory Error with combinatorics/subsets Created: 29/Apr/13 Updated: 08/Apr/14 Resolved: 08/Apr/14
|Reporter:||Mark Engel||Assignee:||Mark Engelberg|
Mac OS X 10.8.3
% java -version
I have an issue with an OutOfMemory error with bigger sets and the subsets command.
I have bigger sets of 1000+ elements and want to lazily create all possible subsets of this set in order to filter out some that are interesting to me.
I was very happy to run into your library as it handles the heavy lifting for me and I only have to do the filtering. Nice!
But if I run this sample code
it returns with an OutOfMemory Error to me.
It would be really nice if this library could calculate subsets of bigger lists without running into memory problems.
I posted this question on StackOverflow with more information:
And people replied that they don't have this issue. Is this an issue with my platform or is this an issue with the memory usage of subsets?
If I can be of any help, just let me know.
|Comment by Stefan du Fresne [ 29/Apr/13 5:29 AM ]|
I get this as well, 2009 MBP, with any (range x) higher than 18.
|Comment by Mark Engel [ 29/Apr/13 8:32 AM ]|
Great to have the problem reproduced at another computer.
I just found an article describing an OutOfMemory Error with mapcat, which is used in the subsets function
|Comment by Andy Fingerhut [ 02/May/13 2:30 PM ]|
Patch mcomb-2-allow-subsets-to-use-less-memory-v1.txt dated May 2 2013 seems to fix this problem.
range returns a chunked sequence, and when map processes a chunked sequence it preserves the chunks. Chunks are little Java arrays of Object references, pointing at the results, and none of them will be GCed until the entire chunk is finished being processed.
It might be that a few other calls to unchunk wrapped around range calls might be useful in the math.combinatorics library, but certainly not all of them.
|Comment by David James [ 23/Jun/13 6:04 PM ]|
Thanks Andy, that worked for me!
Andy's patch, applied to my fork:
|Comment by Andy Fingerhut [ 08/Apr/14 8:24 AM ]|
Mark, any thoughts on this patch? The reason for the memory exhaustion without the patch is a bit subtle, and I can try explaining it differently if you are interested.
|Comment by Andy Fingerhut [ 08/Apr/14 4:21 PM ]|
Mark Engelberg committed this fix: https://github.com/clojure/math.combinatorics/commit/4b5312218344264c3227f7f814db6c688d0ab2fc
I will close this ticket.