2

How can I avoid the massive amount of ConsPStack that are created by my application? When are these created? My application: https://github.com/Jire/Abendigo

enter image description here

Jire
  • 9,680
  • 14
  • 52
  • 87

1 Answers1

3

UPDATE (2016-09-05): the issue has been fixed and is going to be available in Kotlin 1.0.5.

Kotlin reflection implementation is using pcollections to cache KClass instances for different classes. Large amount of ConsPStack instances probably means you're using reflection on a lot of different classes. As I mentioned in another answer, reflection implementation is not optimized at all, so issues like this are somewhat expected at the moment.

If this issue is really critical for you, I would recommend to cut down KClass creation by using Java reflection where possible. Also, as an extreme solution, you can try clearing the contents of the described cache at a particular moment. Here's the corresponding code in Kotlin project. Since the cache (var K_CLASS_CACHE) is private, you'd need to use Java reflection to get access to it.

Alexander Udalov
  • 31,429
  • 6
  • 80
  • 66
  • I am only using reflection to retrieve the `KClass` on a handful of classes (`Byte`, `Short`, `Int`, `Long`, `Float`, `Double`, `Boolean`, and `ByteBuffer`). I do refer to these through a reified generic type of a function which is also only passed these types. – Jire Dec 11 '15 at 02:39
  • As you suggested I was able to remove all of them by replacing all `KClass` with `Class` and using reflection to get the Java class via `Example::class.java` :-) – Jire Dec 11 '15 at 03:25