Unity3d – Do I need to destroy gameobject AND script?

Unity3d – Do I need to destroy gameobject AND script?

From proper leak protection do I need to delete both of these or will getting rid of one take care of both?
Currently I am destroying the script AND the gameobject
private void OnDestroy() {
    Destroy(this.gameObject);
    Destroy(this);
}

Solutions/Answers:

Answer 1:

You only need to destroy the GameObject.

By destroying the GameObject (Destroy(this.gameObject);), you also destroy the script (Destroy(this)) automatically.

Destroying the script simply removes the component from the GameObject. Destroying the GameObject removes all of its components, and the GameObject itself.

But there is an issue with your code. OnDestroy() is called when the component is being destroyed. (This could be because the component is destroyed, or its GameObject.) So calling the code in there is probably not what you want.

References