nanoseconds | 在垃圾收集中花费的最大纳秒数。 |
bool 如果在方法返回时有其他垃圾收集工作仍在进行,则返回 true;如果垃圾收集已完成,则返回 false。如果增量垃圾收集未启用或是在当前平台上不受支持,也返回 false。
在 nanoseconds
参数指定的持续时间内执行增量垃圾收集。
如果增量垃圾收集已启用,则 CollectIncremental()
会运行增量垃圾收集,最多达到指定数量的纳秒。当经过了指定时间量,或是没有更多垃圾收集工作要进行时,方法会返回。请注意,垃圾回收器使用底层平台计时器,其分辨率可能会低至数微秒。换句话说,将值更改数纳秒可能会没有效果。
当知道需要特定时间量来等待某个事件发生,并且要使用此时间让垃圾回收器运行时,可使用此方法。
如果增量垃圾收集未启用,则此方法不执行任何操作并返回 false(IsIncremental 属性必须为 true 才能使用此方法)。
在 PlayerSettings 中为项目启用增量垃圾收集。可以使用 IsIncremental 检查是否启用了增量垃圾收集。
另请参阅:incrementalTimeSliceNanoseconds。
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.