开发者

Simple Java chat client uses more memory whenever a new message comes

We're writing a 开发者_如何学编程simple chat server/client with 2 of my friends(all of us are new programmers). Last night when we run our first running release, and we realized that our client is using more memory whenever a new message comes(I tried it with and without gui and in both situations it still uses more memory with new messages).

You can inspect our code at https://github.com/osa1/simple-chat . Run Server and then Client to test.

I'm using XChat for IRC, and after thousands of lines of text, it still uses same amount of memory. We are trying to make our app like this. We need advices about our code and memory problem.

Thanks and sorry for my english.


I haven't checked your code, but are you removing old chat messages or are you keeping references to them?

You could use a memory profiler to see if you really are leaking memory, but a growing memory can be natural, unless you in the end get an out of memory exception.


Use jvisualvm in the Oracle Java 6 JDK to memory profile your application to see where the memory goes.


We are keeping all messages to show them in client's JTextPane(like any other chat client)

You have your response. The memory consuption grow because you store your messages to display them. So of course memory will grow as the number of messages increase.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜