protected void OnDestroy()
{
Instance = null;
if (this.discoveryClient != null)
{
discoveryClient.RemoveListener(discoveryClientAdapter);
discoveryClient.Dispose();
discoveryClient = null;
if (discoveryClientAdapter != null)
{
discoveryClientAdapter.Dispose();
discoveryClientAdapter = null;
}
}
if (this.sharingMgr != null)
{
// Force a disconnection so that we can stop and start Unity without connections hanging around
this.sharingMgr.GetPairedConnection().Disconnect();
this.sharingMgr.GetServerConnection().Disconnect();
// Release the XTools manager so that it cleans up the C++ copy
this.sharingMgr.Dispose();
this.sharingMgr = null;
}
// Forces a garbage collection to try to clean up any additional reference to SWIG-wrapped objects
System.GC.Collect();
}