4

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).

Monis Iqbal
  • 1,987
  • 7
  • 26
  • 42
  • Scala is a statically-typed language and therefore it should qualify to be used in large projects which may impose space considerations for the jvm process. – Monis Iqbal Dec 04 '09 at 08:10

3 Answers3

3

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.

Daniel C. Sobral
  • 295,120
  • 86
  • 501
  • 681
2

I don't have substantiation for this, but my feeling is that if you're writing any non-trivial program, the amount of space taken up for your program's "real" data will vastly dwarf the amount of space taken up by a few extra function-as-class definitions.

In other words, I wouldn't worry about it.

Carl Smotricz
  • 66,391
  • 18
  • 125
  • 167
1

It is a proven mathematical fact that the number of classes you generate with first-class functions will be able to asymptotically approach, but never surpass, the number of compiled classes in the full Spring distribution. Don't worry, those pioneers will deal with the permgen issues first!

Mitch Blevins
  • 13,186
  • 3
  • 44
  • 32