1、Destory
public static voidDestroy(Objectobj, floatt= 0.0F);
Description
Removes a gameobject, component or asset.
The objectobjwill be destroyed now or if a time is specifiedtseconds from now. Ifobjis aComponentit will remove the component from theGameObjectand destroy it. Ifobjis aGameObjectit will destroy theGameObject, all its components and all transform children of theGameObject. Actual object destruction is always delayed until after the current Update loop, but will always be done before rendering.
2、Object.DestroyImmediate
public static voidDestroyImmediate(Objectobj, boolallowDestroyingAssets= false);
Description
Destroys the objectobjimmediately.
Use this function with care since it can destroy assets permanently and immediately. Also note that you should never iterate through arrays and destroy the elements you are iterating over. This function should only be used when writing editor code.
In game code you should useObject.Destroyinstead ofObject.DestroyImmediate. You are strongly recommended to use Object.Destroy always. Destroy is executed at a safe time. DestroyImmediate happens immediately.
总结:Destory会在场景中动态删除对象、资源等,并不会在内存中销毁并释放,会有GC来决定什么时候销毁,避免频繁对内存读写操作。DestoryImmediate会立即从内从中释放并销毁对象。