question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reduce memory usage for ContiguousSet.asList()

See original GitHub issue

I 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:open
  • Created 7 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
lowassercommented, Feb 6, 2017

We ended up doing a thing where we provided a magic private API for Guava’s own DiscreteDomains, (integers(), longs(), and doubles()) 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/aaae2e9a6b9cab0429f4589f89603742f28f6bd0

1reaction
lowassercommented, Jan 25, 2017

Yes, 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found