Scala memory leak and processes (memory Leak)

Asked

Viewed 292 times

10

I have a fairly complex system in Scala, with multiple threads and simultaneous system calls. This system is having some problem, because busy memory grows over time.

The image below shows the memory occupation of the machine over a day. When it reaches the limit, the process falls and I put a watch-dog to lift it again. inserir a descrição da imagem aqui

I periodically run the command

jcmd <pid> GC.run

And it makes the memory not grow so fast, but still the problem persists.

I did an analysis with the jvisualvm, comparing the heap in 2 different moments, with 40 minutes of difference. The image below shows a comparison between the heap at time 1 and the heap at time 0. Note that there is a considerable increase in instances of some classes, such as ConcurrentHashMap$HashEntry, SNode, WeakReference, char[] and String and various package classes scala.collection.concurrent.

What might be causing my memory Leak?

Objetos vazando memória

Edit 1: Investigating by Jvisualvm, I noticed that the objects of the class Cnode and Inode are in Triedmap, which in turn are instantiated in the class sbt.Trapexit$App. See the hierarchy of objects in the figure:

hierarquia de objetos

Post in English

  • It may be that there is a memory Leak because of the java Weak References in Snode. Some (s) part of the code may be causing this. http://www.scala-lang.org/api/2.10.2/index.html#scala.ref.Weakreference

  • 1

    Buddy, take a look at this tutorial. After a scan in your code again. :)

  • I looked at the article, Fabio, but it doesn’t help much... I can not find in my code any point where I am storing objects that do not lose references, at least not that I have identified...

1 answer

4

These objects are all part of the scala.collection.concurrent.TrieMap. As, from what you indicated, who uses this is the SBT, my suggestion is that you stop using the SBT to start your application.

Use a SBT plugin like sbt-one-jar, sbt-Assembly or sbt-proguard that generates a JAR containing all dependencies, so you can start your application with java -jar sua-aplicacao.jar.

  • I don’t understand... Which competing maps? I don’t use competing maps in my code. And how to check the number of elements in a competing map?

  • 1

    @Danielcukier If Voce does not use, some library you are using. There, really, I can not recommend much, because who is consuming memory is this library -- or whatever is using competing map.

  • take a look at the new figure

  • @Danielcukier Are you running the application with SBT? Is it by any chance a Play application, or is there some other reason for you to use SBT?

  • Not Play, but run using sbt yes. Use for convenience... sbt run

  • @Danielcukier Okay, I changed my answer based on that.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.