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,552評論 5 6
  • **2014真題Directions:Read the following text. Choose the be...
    又是夜半驚坐起閱讀 9,940評論 0 23
  • 這段時間每次翻看朋友圈,都能讀到大學同學記錄的生活點滴,有時不經意的一句話就觸動了我,由此我也想記點生活中的瑣碎,...
    jiaoya閱讀 307評論 0 1
  • 1 正是秋風乍起黃葉飄零時,卻不經意地又到黃昏。 勤奮好學的女生都早早地去了教室,酷愛運動的男生都在運動場上揮灑自...
    老少女簌簌閱讀 412評論 0 2
  • 葉在深秋換上華裝 隨風起舞 又碾落成塵 獻上最后的生命禮贊 你在深秋帶了紅色圍巾 手揣口袋 卻始終冰涼 等待殘葉的...
    蕪城花開閱讀 546評論 0 3