Unity3d Destory&DestoryImmediate

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会立即从内从中释放并销毁对象。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • PLEASE READ THE FOLLOWING APPLE DEVELOPER PROGRAM LICENSE...
    念念不忘的阅读 13,562评论 5 6
  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 9,959评论 0 23
  • 这段时间每次翻看朋友圈,都能读到大学同学记录的生活点滴,有时不经意的一句话就触动了我,由此我也想记点生活中的琐碎,...
    jiaoya阅读 307评论 0 1
  • 1 正是秋风乍起黄叶飘零时,却不经意地又到黄昏。 勤奋好学的女生都早早地去了教室,酷爱运动的男生都在运动场上挥洒自...
    老少女簌簌阅读 413评论 0 2
  • 叶在深秋换上华装 随风起舞 又碾落成尘 献上最后的生命礼赞 你在深秋带了红色围巾 手揣口袋 却始终冰凉 等待残叶的...
    芜城花开阅读 546评论 0 3