我正在編寫遊戲,當我嘗試向服務器發送聊天消息時,出現奇怪的內存泄漏。 發送字符串: 聊天¥測試 假作:爲什麼我無休止地追加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();
}
我不知道爲什麼發生這種情況,有人可以幫我嗎? 我使用'¥'來分割字符串中的變量,之前沒有給我任何問題,所以我懷疑它與它有任何關係。
謝謝。
getText如何工作?這可能是因爲您添加了相同的文本而不是內存泄漏,但是您要求服務器發送的文本存在範圍問題。 –
兩件事...大多數人使用逗號分隔,我敢肯定,你只是遞歸調用sendChat。 – Max
無盡的循環不屬於內存泄漏問題的類。 –