Smack:是否有必要(甚至可能)明确关闭聊天?
使用 Smack 库打开 XMPP 聊天后,是否有必要(甚至可能)显式关闭聊天?
After opening an XMPP Chat using the Smack library, is it necessary (or even possible) to explicitly close a Chat?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您只需删除自己对它的引用,它最终就会自行消失。它仅由 ChatManager 内的弱引用保存,因此最终会被 GC 回收。
如果您不想在 Chat 类等待 GC 时接收更多聊天消息,那么您也应该删除侦听器。
You simply drop your own references to it, and it will eventually disappear on it's own. It is only held by weak references inside the ChatManager so it will get GC'ed eventually.
You should probably remove your listeners as well though, if you don't want to receive any more chat messages while the Chat class is waiting to be GC'ed.
就协议而言,您可以实施XEP-85(聊天状态通知)以让其他人对方知道你已经关闭了聊天。
Protocol-wise, you can implement XEP-85 (Chat State Notifications) to let the other side know that you have closed the chat.
如果您使用 SMACK API,则无需关闭聊天。当您注销或关闭连接时,它将自动关闭。
No not necessary to close chat if you are using SMACK API. When you log out or close connection it will be automatically closed.
我有一个侧面板,显示所有打开的聊天。它允许用户删除任何打开的聊天记录。如果关闭连接,所有打开的聊天都会消失,而不仅仅是被删除的聊天。我也四处查看,似乎没有办法显式销毁聊天,因为垃圾收集可能需要很长时间才能收集对象。
I have a side panel that shows all the open chats. It allows the user to delete anyone of the open chats. If you close the connection, then all the open chats disappear and not just the one that is deleted. I poked around as well, doesn't seem like there's a way to explicitly destroy the chat as garbage collection may take a long time to collect the object.
请遵循此错误报告,因为目前无法关闭聊天。
但由于这个问题已经被报道并承认它可以在下一个版本中修复。
Please follow this bug report, because currently it's not possible to close a chat.
But since this had been reported and acknowledge it could be fixed in the next version.