Search code examples
functionscalajvmpermgenfirst-class

Can First-class functions in Scala be a concern for allocating a large PermGen Space in JVM?


Regarding first-class functions in Scala, it is written in the book Programming by Scala:

A function literal is compiled into a class that when instantiated at run-time is a function value.

When there will be many first-class functions used in a program, will this affect the JVM's PermGen space? because instead of simple functions the compiler is generating classes for each variation of the function value (e.g. in the case of varied definitions of partially applied functions).


Solution

  • The memory profile is certainly going to be different than that of normal Java programs, though you can tune pretty much any memory parameter on the JVM.

    All I can say, however, is that in one year of deep involvement in the Scala community, I have never seen anyone complain about this.