While optimizing parts of my code for an upcoming project, I noticed that a connection was leaking memory on the client. In the code, there is a section that sets up an event handler for when the character’s root part touches another special part named “Zone” to trigger the loading of another interface. However, if a character resets, the event handler needs to be updated for the new character. Now, setting all this up is fine, but I am just wondering about one thing.
From what I understand, connections associated with an instance and its descendants are implicitly disconnected when the method Destroy is called on that instance. Yet, when testing to see if the connection associated with the event handler mentioned above would be disconnected once the character was reset, I noticed that the connection still persists even after the character has been destroyed on the server, so I suspected the issue might have something to do with how the client deals with this change. Out of curiosity, I decided to try something. In a new place, I ran Play Solo and switched into Server Mode. I executed the following code in the command bar:
game.Players.JimmyChance.Character:Destroy() wait(10) game.Players.JimmyChance.Character.Parent = workspace
This successfully destroyed the character on the server, and on the client the character was not visible anymore. The code also threw an error after 10 seconds as expected, but on Client Mode I was able to run the third line after the character had been destroyed. It seems to be the case that the character is removed rather than destroyed, so I was just curious as to why this is.