1.what is the main disadvantage of garbage collection?

Typically, garbage collection has certain disadvantages, including consuming additional resources, performance impacts, possible stalls in program execution, and incompatibility with manual resource management.

Garbage collection consumes computing resources in deciding which memory to free, even though the programmer may have already known this information.

The penalty惩罚 for the convenience of not annotating object lifetime manually in the source code is overhead, which can lead to decreased or uneven performance.[4]

A peer-reviewed paper came to the conclusion that GC needs five times the memory to compensate for this overhead and to perform as fast as explicit memory management.[5]

Interaction with memory hierarchy effects can make this overhead intolerable in circumstances that are hard to predict or to detect in routine testing.

The impact on performance was also given by Apple as a reason for not adopting garbage collection in iOS despite being the most desired feature.[6]

The moment when the garbage is actually collected can be unpredictable, resulting in stalls (pauses to shift/free memory) scattered throughout a session.

Unpredictable stalls can be unacceptable in real-time environments, in transaction processing, or in interactive programs.

Incremental, concurrent, and real-time garbage collectors address these problems, with varying trade-offs.

The modern GC implementations try to avoid blocking "stop-the-world" stalls by doing as much work as possible on the background (i.e. on a separate thread),

for example marking unreachable garbage instances while the application process continues to run.

In spite of these advancements, for example in .NET CLR paradigm it is still very difficult to maintain large heaps (millions of objects) with resident objects

that get promoted to older generations without incurring noticeable delays (sometimes a few seconds).

Non-deterministic GC is incompatible with RAII based management of non-GCed resources[citation needed].

As a result, the need for explicit manual resource management (release/close) for non-GCed resources becomes transitive to composition.

That is: in a non-deterministic GC system, if a resource or a resource-like object requires manual resource management (release/close),

and this object is used as "part of" another object, then the composed object will also become a resource-like object that itself requires manual resource management (release/close).

2.How do you achieve deterime finalization?

https://www.safaribooksonline.com/library/view/programming-net-components/0596102070/ch04s05.html

The Open/Close Pattern

The Dispose() Pattern

The IDisposable Pattern

Disposing and Error Handling

Finalization的更多相关文章

  1. initialization & finalization

    Delphi 的pas文件中可以有initialization和finalization两个关键字, 1.initialization关键字: 在initialization关键字到finalizat ...

  2. 扯扯Java中Finalization的意义

    这是Stack Overflow上关于Finalizetion意义的两段讨论,这两个观点是互为补充的. 观点1: 垃圾回收器(The garbage collector)自动在后台运行(虽然它也可以被 ...

  3. pytest6-Fixture finalization / executing teardown code(使用yield来实现)

    Fixture finalization / executing teardown code By using a yield statement instead of return, all the ...

  4. finalize()方法什么时候被调用?析构函数(finalization)的目的是什么?

    链接:https://www.nowcoder.com/questionTerminal/d8eab06913084e42b515633604eef7cd?pos=28&mutiTagIds= ...

  5. PEP 442 -- Safe object finalization

    https://www.python.org/dev/peps/pep-0442/ PEP 442 -- Safe object finalization PEP: 442 Title: Safe o ...

  6. initialization 与 finalization 执行顺序 研究

    看GIF: 第二个GIF: DEMO下载:http://files.cnblogs.com/files/del88/InitOrderDemo.zip

  7. .NET面试题系列[5] - 垃圾回收:概念与策略

    面试出现频率:经常出现,但通常不会问的十分深入.通常来说,看完我这篇文章就足够应付面试了.面试时主要考察垃圾回收的基本概念,标记-压缩算法,以及对于微软的垃圾回收模板的理解.知道什么时候需要继承IDi ...

  8. Windbg Extension NetExt 使用指南 【3】 ---- 挖掘你想要的数据 Managed Heap

    摘要 : NetExt中有两个比较常用的命令可以用来分析heap上面的对象. 一个是!wheap, 另外一个是!windex. !wheap 这个命令可以用于打印出heap structure信息. ...

  9. .net垃圾回收机制编程调试试验

    1. 什么是CLR GC? 它是一个基于引用跟踪和代的垃圾回收器. 从本质上,它为系统中所有活跃对象都实现了一种引用跟踪模式,如果一个对象没有任何引用指向它,那么这个对象就被认为是垃圾对象,并且可以被 ...

随机推荐

  1. windows 7 下快速搭建php环境 windows7+IIS7+php

    1.       安装IIS v7.0 控制面板-程序和功能-打开或关闭Windows 功能 测试是否成功安装IIS v7.0,在浏览器输入:http://localhost/ 或者http://12 ...

  2. eclipse git 整合

    最近朋友都推荐使用github管理自己的项目,而且免费用户可以有5个仓库,恰好我也想了解下git,借此机会学习一下.github官方指南使用独立第三方git工具来进行版本控制,并不借助于eclipse ...

  3. vi编辑器的常见使用技巧

    光标移动 在普通模式下, 1.按 h 向左移动光标 按 h + 数字n 可以向右移动 n个字符   比如 h + 5  就是向左移动5个字符 2.按j向下移动光标 3.按k向上移动光标 4.按 l 向 ...

  4. poj 2975 Nim 博弈论

    令ans=a1^a2^...^an,如果需要构造出异或值为0的数, 而且由于只能操作一堆石子,所以对于某堆石子ai,现在对于ans^ai,就是除了ai以外其他的石子 的异或值,如果ans^ai< ...

  5. [转载] Linux poll机制

    原地址:http://hongwazi.blog.163.com/blog/#m=0&t=3&c=poll poll的是一种查询的方式,英文解释 :民意调查 函数原型:int poll ...

  6. tomcat简介及原理解说

    Tomcat简介 作者:杨晓(http://blog.sina.com.cn/u/1237288325) 目录: ----Tomcat背景 ----Tomcat目录 ----Tomcat类加载 --- ...

  7. ScriptManager.RegisterStartupScript方法和Page.ClientScript.RegisterStartupScript() 区别

    ScriptManager.RegisterStartupScript方法 如果页面中不用Ajax,cs中运行某段js代码方式可以是: Page.ClientScript.RegisterStartu ...

  8. lintcode:删除链表中指定元素

    题目 删除链表中等于给定值val的所有节点. 样例 给出链表 1->2->3->3->4->5->3, 和 val = 3, 你需要返回删除3之后的链表:1-> ...

  9. lintcode:带环链表

    带环链表 给定一个链表,判断它是否有环. 解题 定义两个指针p1 p2 p1每次向前走一步 p2每次向前走两步 当p2能赶上p1的时候说明有环 /** * Definition for ListNod ...

  10. GDB调试方法精粹

    http://blog.chinaunix.net/uid-26922071-id-3756018.html 一.多线程调试 1. 多线程调试,最重要的几个命令: info threads       ...