Spark memory leak problem and solution

After the client accepts multiple conversation requests or opens multiple conference rooms, the heap memory will be exhausted and it will exit. Using jconsole detection, it can be found that its occupancy of heap memory only increases and does not decrease. Using jprofile , it can be found that the GroupChatRoom object still exists after closing the chat room. , and only increase but not decrease can not be garbage collected and eventually exhaust the heap memory, the console throws OuOfMemoryError.

 

jprofile can view the References Graph of the remaining object, analyze which references to it from the left will prevent it from being garbage collected, and can also calculate the path to GC (garbage collection), from here, you can check whether there is a global path in the path object. Finally, it is found that ChatTranscriptManager saves a persistent reference to GroupChatRoom, it does not properly remove ChatRoom from lastMessage, and the ChatRoomListener registered by it and persistentChatRoom (ChatRoom) called by other classes are inconsistent in the filtering of ChatRoom when saving chat records. The former Only accepts ChatRoomImpl instances, which accept all ChatRoom instances (including GroupChatRoom instances), it is recommended to use the unified filterChatRoom(ChatRoom) to filter the appropriate ChatRoom, and remove the ChatRoom key from lastMessage when chatRoomClosed.

 

At the same time, it can also be found that MultiUserChat only rises and does not fall. The same analysis can find that there is such a reference chain MultiUserChat <- presenceListener <- packetMultiplexor <- roomListenerMultiplexor <- XMPPConnection, and finally this is a global object that will only expire when the client exits, Ignite You can find some posts about memory leak on the Realtime forum and find that there is a fix patch that removes the reference to packetMultiplexor from roomListenerMultiplexor in the finalize method of MultiUserChat . Obviously, this method is unreliable, and the removal action should be executed when leaving .

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326359116&siteId=291194637