• Garbage Collection


     The Algorithm of Garbage Collection

    Garbage collector makes sure if a particular memory block should to be freed by examining if it is occupied by the garbage objects application will no longer consume.

    Every application owns a collection of pointers to memory address. Each entry in the collection is usually called as root. A root is actually a particular pointer to the block of memory region which is occupied by certain garbage object which should not be released. Theses objects include: global reference variables and static reference variables, all local variables and parameter variables in thread stack in a method, and the CPU register to a reference variables. When compiling a particular IL code, the JIT compiler will generate an internal table which stores not only the byte offset of each CPU instruction but also the all the roots in their scope.

    When garbage collector begins to execution of garbage collection, it assumes firstly that all objects allocated in managed heap can be garbage collected. In other word, it assumes that each of the objects allocated in managed heap is not be referred in a particular root. Then garbage collector scans each of the roots, and then draws a graphic which contains the entire objects referred directly or indirectly by the roots recursively. The objects contained in the graphic are all called as reachable objects since all the objects are reachable from the roots. All the reachable objects can be considered as the ones which should not currently be garbage collected. At the point, garbage collector can make distinct garbage object from the reachable objects.

     After making sure all the objects which can be garbage collected, the garbage collector then scans the managed heap to seek for a block of contiguous memory region occupied by garbage objects and the small memory region will be let alone. If such a contiguous memory region is found out, garbage collector will remove some non-garbage objects into it. Obviously, the former pointers to the objects become invalid, so garbage collector must revise the root and make them to re-point to the objects correctly, and all the pointers to the objects will be revised as well.

  • 相关阅读:
    ubuntu 防止软件包自动更新
    记录一个开头带有&#x的特征数据的解码
    从一次失败的微信小程序抓包、反编译经历中学习反思
    Python爬虫处理奇葩的请求参数payload
    python爬虫
    python爬虫处理在线预览的pdf文档
    python高级—— 从趟过的坑中聊聊爬虫、反爬、反反爬,附送一套高级爬虫试题
    djangorestframework+vue-cli+axios,为axios添加token作为headers踩坑记
    django 问题综合
    vue(9)—— 组件化开发
  • 原文地址:https://www.cnblogs.com/lingxzg/p/517877.html
Copyright © 2020-2023  润新知