This page has been translated automatically.
视频教程
界面
要领
高级
实用建议
专业(SIM)
UnigineEditor
界面概述
资源工作流程
版本控制
设置和首选项
项目开发
调整节点参数
Setting Up Materials
设置属性
照明
Sandworm
使用编辑器工具执行特定任务
如何擴展編輯器功能
嵌入式节点类型
Nodes
Objects
Effects
Decals
光源
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
编程
基本原理
搭建开发环境
使用范例
C++
UnigineScript
UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
材质和着色器
Rebuilding the Engine Tools
GUI
双精度坐标
应用程序接口
Animations-Related Classes
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes
VR-Related Classes
创建内容
内容优化
材质
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials

垃圾收集器

The Garbage Collector (GC) represents an automatic memory manager responsible for allocation and release of memory for an application. So, developers working with managed code don't have to think about memory management tasks, and write any specific code for this purpose. Automatic memory management helps eliminate common problems, such as forgetting to free an object and causing a memory leak or attempting to access memory for an object that's already been freed. 垃圾收集器(GC)代表自动内存管理器,负责为应用程序分配和释放内存。因此,使用托管代码的开发人员不必考虑内存管理任务,也无需为此编写任何特定的代码。自动内存管理有助于消除常见问题,例如忘记释放对象并导致内存泄漏或尝试访问已释放对象的内存。

Here are the benefits the Garbage Collector provides:以下是垃圾收集器提供的好处:

  • Frees developers from having to release memory manually.使开发人员不必手动释放内存。
  • Efficiently allocates objects on the managed heap.有效地在托管堆上分配对象。
  • Reclaims objects that are no longer used, clears their memory, keeping the memory available for future allocations. Managed objects automatically get clean content to start with, so you don't have to initialize each and every data field in their constructors.回收不再使用的对象,清除其内存,使内存可用于将来的分配。托管对象会自动获取干净的内容,因此您不必初始化其构造函数中的每个数据字段。
  • Provides memory safety making sure that the content of an object cannot be used by another object.提供内存安全性,确保一个对象的内容不能被另一个对象使用。

Garbage Collection Modes垃圾收集模式#

UNIGINE's Garbage Collector offers you the following set of modes (Engine.GCMode) making the process of garbage collection management flexible: UNIGINE的垃圾收集器为您提供以下模式(Engine.GCMode),使垃圾收集管理的过程变得灵活:

  • DEFAULT (default) - default C# garbage collector mode. In this case heavy spikes and excessive memory consumption are imminent if you don’t manage your objects properly and do not use the Dispose() method. DEFAULT(默认)-默认的C#垃圾收集器模式。在这种情况下,如果您不能正确地管理对象并且不使用Dispose()方法,则可能会出现尖峰和过多的内存消耗。
  • USE_MEMORY_PRESSURE - passes the information about C++ memory consumption to C#. This results in more frequent GC calls preventing the application from eating too much memory right after startup and removing heavy spikes. USE_MEMORY_PRESSURE-将有关C ++内存消耗的信息传递给C#。这会导致更频繁的GC调用,从而阻止应用程序在启动后立即占用过多内存并消除大量的峰值。
  • EVERY_FRAME - the garbage collector is called every frame. This results in overall performance reduction, but removes heavy spikes. EVERY_FRAME-每帧都调用垃圾收集器。这会导致整体性能下降,但会消除尖峰。
  • WORLD_SHUTDOWN - the garbage collector is called on closing the world. This mode is ideal if the number of memory allocations is your code is insignificant. WORLD_SHUTDOWN-在关闭世界时调用垃圾收集器。如果您的代码中的内存分配数量微不足道,则此模式是理想的。

You can set Garbage Collector's mode in the SystemLogic::Init() method or anywhere in your code, and you can change it when necessary, depending on the current situation. It is also safe to do it in your C# components.可以在SystemLogic::Init()方法中或在代码的任何位置设置垃圾收集器的模式,并且可以根据当前情况在必要时进行更改。在您的C#组件中这样做也是安全的。

源代码 (C#)
class UnigineApp
{
  class AppSystemLogic : SystemLogic
  {
    // ...

    public override bool Init()
    {
      Engine.GCMode = Engine.GCMODE.EVERY_FRAME;
      // ...
      return true;
    }
    // ...
}
最新更新: 2020-10-10
Build: ()