Having the following script:
public class Code : MonoBehaviour
{
public UnityEvent MyEvent = new UnityEvent();
public static Code Instance;
void OnEnable()
{
Instance = this;
}
}
Another separate object subscribes to the Event created and destroys itself without unsubscribing from the Event:
public class Player : MonoBehaviour
{
void Start()
{
Code.Instance.MyEvent.AddListener(OnCall);
Destroy(gameObject);
}
void OnCall()
{
Debug.Log("Called");
}
}
Will the event, that is holding a pointer to the object, prevent the garbage collection and release of memory from the destroyed object?