Finalization
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的更多相关文章
- initialization & finalization
Delphi 的pas文件中可以有initialization和finalization两个关键字, 1.initialization关键字: 在initialization关键字到finalizat ...
- 扯扯Java中Finalization的意义
这是Stack Overflow上关于Finalizetion意义的两段讨论,这两个观点是互为补充的. 观点1: 垃圾回收器(The garbage collector)自动在后台运行(虽然它也可以被 ...
- pytest6-Fixture finalization / executing teardown code(使用yield来实现)
Fixture finalization / executing teardown code By using a yield statement instead of return, all the ...
- finalize()方法什么时候被调用?析构函数(finalization)的目的是什么?
链接:https://www.nowcoder.com/questionTerminal/d8eab06913084e42b515633604eef7cd?pos=28&mutiTagIds= ...
- PEP 442 -- Safe object finalization
https://www.python.org/dev/peps/pep-0442/ PEP 442 -- Safe object finalization PEP: 442 Title: Safe o ...
- initialization 与 finalization 执行顺序 研究
看GIF: 第二个GIF: DEMO下载:http://files.cnblogs.com/files/del88/InitOrderDemo.zip
- .NET面试题系列[5] - 垃圾回收:概念与策略
面试出现频率:经常出现,但通常不会问的十分深入.通常来说,看完我这篇文章就足够应付面试了.面试时主要考察垃圾回收的基本概念,标记-压缩算法,以及对于微软的垃圾回收模板的理解.知道什么时候需要继承IDi ...
- Windbg Extension NetExt 使用指南 【3】 ---- 挖掘你想要的数据 Managed Heap
摘要 : NetExt中有两个比较常用的命令可以用来分析heap上面的对象. 一个是!wheap, 另外一个是!windex. !wheap 这个命令可以用于打印出heap structure信息. ...
- .net垃圾回收机制编程调试试验
1. 什么是CLR GC? 它是一个基于引用跟踪和代的垃圾回收器. 从本质上,它为系统中所有活跃对象都实现了一种引用跟踪模式,如果一个对象没有任何引用指向它,那么这个对象就被认为是垃圾对象,并且可以被 ...
随机推荐
- 【递推】BZOJ 4300:绝世好题
4300: 绝世好题 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 564 Solved: 289[Submit][Status][Discuss] ...
- CoreData (表结构变化处理)
引言: Core Data 是 iOS 3.0 以后引入的数据持久化解决方案,其原理是对SQLite的封装,是开发者不需要接触SQL语句,就可以对数据库进行的操作. 其编码方式和原理结构方面较为特殊, ...
- HTTP persistent connection
http://en.wikipedia.org/wiki/HTTP_persistent_connection
- ASP.NET MVC与RAILS3的比较
进入后Web年代之后,MVC框架进入了快速演化的时代,Struts等垂垂老矣的老一代MVC框架因为开发效率低下而逐渐被抛弃,新一代的MVC则高举敏捷的大旗,逐渐占领市场,其中的代表有Rails (ru ...
- flashdevelop 开发技巧
FlashDevelop用来编写AS3代码,Flash CS5用来编辑程序所需要的资源(图片,声音-),Flash CS5自带有Flex SDK,在目录 C:\Program Files\Adobe\ ...
- nginx规则和ci的支持
CI框架下nginx重写规则,不再404 http://blog.csdn.net/EI__Nino/article/details/8599304 server { listen 80; serve ...
- C# Task的使用---Task的启动
.NET 4.0包含的新名称空间System.Threading.Tasks,它包含的类抽象出了线程功能.任务表示应完成的某个单元的工作.这个单元的工作可以在单独的线程中运行,也可以以同步的方式启动一 ...
- Java:内部类
1.内部类的定义: 一个内部类可以定义在另一个类里,可以定义在函数里,甚至可以作为一个表达式的一部分. 2.内部类的分类: Java中的内部类共分为四种: 成员内部类member inner clas ...
- Java7编程 高级进阶学习笔记--嵌套类
定义: 在一个类中定义的类叫做嵌套类. 作用: 1.允许对相关类进行逻辑分组 2.增强了代码的封装性 3.使代码具有更强的可读性和维护性 使用方式: package com.cmz.baseTest; ...
- servlet中中文乱码问题
在web项目中经常回碰到中文乱码的问题,特此整理一下,有不足的地方,希望大家纠正. 1从前台往后台传数据,.以get方式发送请求,发送的参数不乱,但是后台接收到参数乱码 在Tomcat的server. ...