about Enum.values() memory allocation
Ron Shapiro
ronshapiro at google.com
Wed Jul 25 11:17:30 UTC 2018
It's a bit of indirection, but can for (YourEnum e :
EnumSet.allOf(YourEnum.class)) {} do the trick? It will still allocate, but
likely only one instance instead of a full array.
On Wed, Jul 25, 2018, 5:23 AM Michael Rasmussen <
Michael.Rasmussen at roguewave.com> wrote:
> With condy being added in Java 11, this could potentially be a use-case
> for that ?
>
>
> for (EnumType e: const(EnumType.values())) { ... }
>
>
> Or perhaps it's time to add a List<E> valuesList(); to enum types, that
> returns an immutable List of the values?
>
>
> /Michael
> ------------------------------
> *From:* compiler-dev <compiler-dev-bounces at openjdk.java.net> on behalf of
> nezih yigitbasi <nezihyigitbasi at gmail.com>
> *Sent:* 25 July 2018 08:23:57
> *To:* compiler-dev at openjdk.java.net
> *Subject:* about Enum.values() memory allocation
>
> Hi,
> I recently noticed in our app that Enum.values() allocates a significant
> amount of memory when called in a tight loop as it clones the constant
> values array (which is probably for immutability, and I can understand
> that). I found that the same issue has been discussed back in 2012:
> http://mail.openjdk.java.net/pipermail/compiler-dev/2012-March/004210.html
>
> Are there any plans to address this issue going forward?
>
> Thanks!
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20180725/57356276/attachment-0001.html>
More information about the compiler-dev
mailing list