These are chat archives for TheHolyWaffle/TeamSpeak-3-Java-API

2nd
Jan 2017
xNarkon
@xNarkon
Jan 02 2017 22:01

Hi guys, there is some kind of memory leak in the code or I'm doing something wrong (Java is not my best language and is a little specific)

In my case, everytime after client disconnection memory increasing by ~0.2-1mb but it shouldn't or am I wrong? (Even when I'm running the plain example from the repo) - GC just do not cleaning something, but I don't know what...

somefriggnidiot
@somefriggnidiot
Jan 02 2017 22:02
Does this happen if the same client were to disconnect multiple times?
xNarkon
@xNarkon
Jan 02 2017 22:03
exactly
I noticed this only when the same client disconnect multiple times as you said.
somefriggnidiot
@somefriggnidiot
Jan 02 2017 22:05
Curious... I'm noticing the same thing in my program.
Actually, it appears only to be happening when a user connects for me.
xNarkon
@xNarkon
Jan 02 2017 22:10
Something must be wrong in the repo, @TheHolyWaffle should check this out...
Roger Baumgartner
@rogermb
Jan 02 2017 22:13

@somefriggnidiot @xNarkon Are you sure this isn't just because the GC hasn't done a full mark-and-sweep cycle?

Can you try launching Java with the VM option -XX:+PrintGCDetails and calling System.gc() every once in a while so we get some good logs?

Roger Baumgartner
@rogermb
Jan 02 2017 22:22

See, my problem is the following: we're not treating client-left events any different from other events. We're not storing them anywhere and we're not adding them to any kind of collection.

There is one allocation, the created object is shared with the event listeners, and as long as you're not keeping a reference to those events in your listeners they should eventually be GC'd.

xNarkon
@xNarkon
Jan 02 2017 22:24
Can you post sample on pastebin or somewhere?
Roger Baumgartner
@rogermb
Jan 02 2017 22:28
for what exactly? Launching Java with that VM option should be trivial, forcing the GC to run every few seconds can simply be done by spinning up a new Thread
new Thread(new Runnable() {
        @Override
        public void run() {
            while (!Thread.interrupted()) {
                try {
                    System.gc();
                    Thread.sleep(10000); // 10 s
                } catch (InterruptedException ie) {
                    break;
                }
            }
        }
}).start();
Please keep in mind I just typed this out in this chat window - there's almost certainly a problem with this snippet
But I think the intention is clear enough
xNarkon
@xNarkon
Jan 02 2017 22:45
Roger Baumgartner
@rogermb
Jan 02 2017 23:01
I don't see any sign of a memory leak in this log. The young generation cleans down to 0 kB, the old generation always stays around 2680 - 2700 kB and isn't growing
And if you mention noticing a memory leak, I'd assume there to be some kind of substantial memory growth over time, no?
xNarkon
@xNarkon
Jan 02 2017 23:02
Yes
Roger Baumgartner
@rogermb
Jan 02 2017 23:03
But there isn't any, at least not in these logs :stuck_out_tongue:
xNarkon
@xNarkon
Jan 02 2017 23:05
So this is normal in java that the memory is growing over time? Thanks for help. I will test it in production in a few days and then will see if there is really a memory leak or not.
somefriggnidiot
@somefriggnidiot
Jan 02 2017 23:05
Been checking the usage on mine over the past few minutes. It fluctuates, but I'm 10mb lower than I was 20 minutes ago.
Roger Baumgartner
@rogermb
Jan 02 2017 23:06
Well, it just depends on whether the GC runs or not. In this test we've run the GC every 10 seconds
But in a real-life setting, the GC will only run once some kind of upper memory limit has been reached I think
Basically, Java tries to run the GC as infrequently as possible as doing GC work slows down your program
xNarkon
@xNarkon
Jan 02 2017 23:10
Can I set this upper limit for the memory? Because if I understand memory will grow so long until it reaches an unknown limit. I want to avoid a situation where the bot clogged my memory for other processes.
Roger Baumgartner
@rogermb
Jan 02 2017 23:12
First of all, I've never seen this become a problem since the GC has always kicked in for me before any significant amount of memory has been used. But yes, you can limit the maximum allocatable memory by using the VM option -Xmx123M
where 123M is the amount you want to limit it to
Or see here for how to configure Java 8's default GC
xNarkon
@xNarkon
Jan 02 2017 23:16
Thanks a lot. I appreciate it
Roger Baumgartner
@rogermb
Jan 02 2017 23:16
You're welcome :smile: