C# finding gameobject that created this class, and do I need to clear them?

Hello!
I’m learning now OOP. And I got some questions, about how unity3d works with classes.

First situation:
I’m having a GameObject that has a script:

Bot Script:

public class Bot : MonoBehaviour
{
    void Start () 
    {
        ....EnemysList.Add(new Enemy(this.gameObject, 100));
    }
}

====================

Where Enemy class is this:

public class Enemy : Enemys
{
	public  int EnemysCount;
	private int Health;
	private GameObject Owner;
    
    public Enemy(GameObject WhoCreated,int newHealth)
    {
		EnemysCount++;
		Owner = WhoCreated;
        Health = Health;
    }
	
	public int Master
    {
        get
        {
            //Returning class owner
            return Owner;
        }
    }
}

And Enemy is a part of Enemys class, that stores in a list all new Enemy classes ( EnemysList):

So First question is:
If I want to know who is owner of class from EnemysList(that stores all classes that were created by Bot on Start()), is there better way to access GameObject, than Enemys.EnemysList[0].Master? I mean, that should I really add to class GameObject variable? Or there is another way of doing it?

Second question is:
If my GameObject with Bot script, will be removed, do I need to remove from list that class? Or Unity3d does it by itself? And if I need, how can I remove class from list Enemys.EnemysList[n]?

First question:

I’m a little unclear about what kind of design pattern you’re trying to implement there… It sounds like you’re wanting to create a factory you can create multiple instances of, with each instance maintaining a list of objects it creates? If that’s the case, you’ll want to store a reference to an instance of the factory class in each object it creates (so they can reference their “owner”).

Second question:

After your enemy instance is destroyed, the reference to it in your list will become null, but there will still be an element taken up by that null reference. You can handle removing your enemy from the list by using OnDestroy() in your enemy class (if it inherits from MonoBehaviour) or your enemy class’ destructor (if it doesn’t inherit from MonoBehaviour).

On that note: Be careful with using class constructors and destructors with anything that inherits from MonoBehaviour. Because MonoBehaviours have their constructors and destructors called during events in the editor (begin play, end play, add, duplicate, delete), you can get some odd errors. Generally, when inheriting from MonoBehaviour and attempting to manage initialising and cleaning up objects during play, you should be using Awake() (or Start()) instead of constructors, and OnDestroy() instead of destructors.