为什么我要在Java中无休止地添加字符串
我正在写一个游戏,当我试图向服务器发送聊天信息时,我收到了一个奇怪的内存泄漏。 发送字符串: !聊天测试 变成:
!chat¥test
!chat¥!chat¥test
!chat¥!chat¥!chat¥test
!chat¥!chat¥!chat¥!chat¥test
!chat¥!chat¥!chat¥!chat¥!chat¥test
!chat¥!chat¥!chat¥!chat¥!chat¥!chat¥test
!chat¥!chat¥!chat¥!chat¥!chat¥!chat¥!chat¥test
!chat¥!chat¥!chat¥!chat¥!chat¥!chat¥!chat¥!chat¥test
!chat¥!chat¥!chat¥!chat¥!chat¥!chat¥!chat¥!chat¥!chat¥test
!chat¥!chat¥!chat¥!chat¥!chat¥!chat¥!chat¥!chat¥!chat¥!chat¥test
!chat¥!chat¥!chat¥!chat¥!chat¥!chat¥!chat¥!chat¥!chat¥!chat¥!chat¥test
Ect, ect.
Sending message:
Utils.sendChat(message.getText());
public static void sendChat(String s) {
System.out.println(s);
sendChat("!chat"+Wrapper.commandSplit+s);
}
public static void sendTextLine(String s){
s = s.replace(" ", "[SPACE]");
System.out.println(s);
Wrapper.pw.write(s);
Wrapper.pw.flush();
}
我不知道为什么会这样,有人能帮我吗? 我使用¥来拆分字符串中的变量,以前没有给我任何问题,所以我怀疑这与此有关
谢谢
共 (0) 个答案