Reduce memory usage for ContiguousSet.asList()
See original GitHub issueI was surprised to learn that ContiguousSet.asList()
returns an ImmutableList
which copies the discrete domain values into a new array:
Exception in thread "main" java.lang.OutOfMemoryError: Requested array size exceeds VM limit
at com.google.common.collect.ImmutableCollection.toArray(ImmutableCollection.java:186)
at com.google.common.collect.ImmutableSet.createAsList(ImmutableSet.java:371)
at com.google.common.collect.ImmutableSet.asList(ImmutableSet.java:367)
Can ContiguousSet.asList()
be changed to return a subclass of ImmutableList
which computes the values as requested instead so that a ContiguousSet
can be viewed as a List
to be used with methods that act on lists?
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
java - How i can reduce the memory usage in following code?
Your code is already enough compact. Only two things you can do: use BitSet; use Array in place of the List as you...
Read more >How to Prevent Your Java Collections From Wasting Memory
Here are some tips to high-performance Java collections and advice for making decisions about using collections to keep memory overhead low.
Read more >Class ImmutableDoubleArray - Guava
Access to all collection-based utilities via asList() (though at the cost of allocating garbage). Disadvantages compared to double[] : Memory footprint has ...
Read more >Minimize Java Memory Usage with the Right Garbage Collector
It can be easily initiated with various options: jcmd <pid> GC.run – executing external call; System.gc() – inside the source code; jvisualvm ...
Read more >Manage your app's memory - Android Developers
Learn how you can proactively reduce memory usage while developing for ... The provided onTrimMemory() callback method allows your app to listen for...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We ended up doing a thing where we provided a magic private API for Guava’s own DiscreteDomains, (
integers()
,longs()
, anddoubles()
) to use that supported the “nice” ImmutableList, but we didn’t expose a way for external DDs to use it. Hopefully that will alleviate the worst of the problems. https://github.com/google/guava/commit/aaae2e9a6b9cab0429f4589f89603742f28f6bd0Yes, absolutely, knowing it’s a list of exactly one type that you know how to offset lets you do this. That isn’t the case for all possible DiscreteDomains, though.