The sprIT team has reported that they have a memory leak when running the agent for some amount of time without it being connected to the CMR. Although this is not a real usage scenario for us (why would Agent be there without the CMR), I still had a look on the heap dump they provided. And they were correct the Agent does make a memory leak.
Apparently every time we try to connect to the CMR we create a new instance of the kryonet Client for communication. If connect fails we do allow this object to be garbage collected, but it's obviously not collected.. Seams like the problem is that Client creates a thread when being constructed (Client thread) and this one has a hard reference to the Client itself. And this thread seams to stay alive although we call clearly Client.stop() method when connection fails.
In my opinion we have two options here:
Keep current approach, but check how to terminate the update thread as well (maybe calling Client.close()) as well.
Create only one client instance and just executed connect() method when connection is asked for
Attached the screens from MAT.. As it can be seen we have 653 instances of Client object.. And the GC root path shows that only reference to the Client is the thread itself..
Update: The threads are not terminated not because we are doing something wrong, but because they hit the ePoolWait() method (see updated pic). Most likely they hit this method during the close method or something like this.. I will try to test to see if we can avoid this..
which updated pic are you referring to?
Pushed before commit.. Sorry..