Why you need to understand garbage collection
Why you need to understand garbage collection
I’ve been interviewing lots of C# developers recently, and one of my stock questions is “how does the .NET garbage collector know when you’ve finished using an object?” The reason I ask is this because having an understanding of the underlying workings of .NET such as the garbage collector generally indicates that the candidate is a good developer. It shows that they care about how the tools and technologies they are using actually work, and this enables them to write better code.
However, I have been surprised at how many .NET developers, even ones who give good answers to other technical questions, really seem to struggle with this topic. This is particularly noticeable with younger C# developers – those who have only used garbage collected languages in their entire career.
I have a theory as to why this is: when older developers who got started in C/C++ started to try out garbage collected languages like C# and Java, we were initially very suspicious. Freeing memory was such a critical part of how we were used to writing code, that we wanted to know exactly how the garbage collector knew what to collect, when it would run, and we even wanted to take control ourselves and force it to run on demand.
But people who have only ever programmed with garbage collected languages have not been scarred by the horrors of debugging memory leaks, or dereferencing pointers to already freed memory. And so there isn’t such a strong incentive to delve into the inner workings of the garbage collector.
This is unfortunate, as having a solid understanding of the garbage collector is extremely useful when trying to write high performing code. It can be particularly valuable in applications like digital audio, where you are working at low latencies in real-time, and even a small delay due to the garbage collection could cause a glitch in playback. You learn techniques such as reusing byte arrays rather than repeatedly creating new ones, in order to minimise the amount of work the garbage collector needs to do. It will also help you understand why certain objects need to be “pinned” to allow you to use them in conjunction with unmanaged code.
So if you’re a C# developer and you don’t yet have a good understanding of what the garbage collector is and how it works, why not do yourself a favour and educate yourself a bit? It won’t take a huge amount of time, and there are plenty of good articles on the subject. And if you’ve got a Pluralsight subscription (which I highly recommend!), then my friend Elton has a whole module explaining the garbage collector in his IDisposable best practices course.
Why you need to understand garbage collection的更多相关文章
- How Garbage Collection Really Works
Java Memory Management, with its built-in garbage collection, is one of the language's finest achiev ...
- Java Garbage Collection Basics--转载
原文地址:http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/gc01/index.html Overview Purpose ...
- The Impact of Garbage Collection on Application Performance
As we’ve seen, the performance of the garbage collector is not determined by the number of dead obje ...
- Garbage Collection Optimization for High-Throughput and Low-Latency Java Applications--转载
原文地址:https://engineering.linkedin.com/garbage-collection/garbage-collection-optimization-high-throug ...
- Unity性能优化(3)-官方教程Optimizing garbage collection in Unity games翻译
本文是Unity官方教程,性能优化系列的第三篇<Optimizing garbage collection in Unity games>的翻译. 相关文章: Unity性能优化(1)-官 ...
- AutoReleasePool 和 ARC 以及Garbage Collection
AutoReleasePool autoreleasepool并不是总是被auto 创建,然后自动维护应用创建的对象. 自动创建的情况如下: 1. 使用NSThread的detachNewThread ...
- [翻译]Java垃圾收集精粹(Java Garbage Collection Distilled)
source URL: http://www.infoq.com/articles/Java_Garbage_Collection_Distilled Name: Java Garbage Colle ...
- [Java] 垃圾回收 ( Garbage Collection ) 的步骤演示
关于 JVM 垃圾回收机制的基础内容,可参考上一篇博客 垃圾回收机制 ( Garbage Collection ) 简介 上一篇博客,介绍了堆的内存被分为三个部分:年轻代.老年代.永生代.这篇博文将演 ...
- [Java] 垃圾回收机制 ( Garbage Collection ) 简介
自动垃圾回收( Automatic Garbage Collection ) 自动垃圾回收,是指在堆(Heap)内存上分辨哪些对象还在被使用,哪些对象没有被使用,并清除没有被使用的对象.所以,这里的垃 ...
随机推荐
- Java 之 LinkedList 集合
一.LinkedList 概述 java.util.LinkedList 集合数据存储的结构是链表结构. 特点:增删快,查询慢 LinkedList 是一个双向链表,如下图 注意:该集合实现不是同步 ...
- 链接标签(a 标签)
一.链接标签 单词缩写: anchor 的缩写. 在HTML中创建超链接非常简单,只需用标签环绕需要被链接的对象即可. 语法格式: <a href="跳转目标" target ...
- Java语言的介绍
1. 计算机语言 语言:沟通交流的方式 计算机语言:人与计算机之间的交流方式 java是一门计算机编程语言,也是意大利自行车品牌 软件工程师,java开发工程师 <--------------- ...
- git的基本使用和多人协作合并管理
1.代码版本控制工具 git 分布式 svn 集中式 2.配置git 配置用户名以及邮箱账号,用于记录用户信息 git config --global user.name 'wudaxun' git ...
- App的开发过程(转载)
来源:https://www.cnblogs.com/sanwenyu/p/7234616.html 不同的项目管理模式或许会有完全不同的流程步骤.但是专业性几乎是保证产品质量的唯一准则. App的开 ...
- Axios的简单用法
一转眼Vue 3.0都要发布了,学习使用Vue也有一段时间了,记录一下axios的用法 Axios 是一个基于 Promise 的 HTTP 库,可以用在浏览器和 node.js 中,有点类似于aja ...
- freebsd缓存包与仓库版本不一致
问题描述: pkg install -y lrzsz pkg: cached package lrzsz-0.12.20_4: size mismatch, cannot continue 问题解决: ...
- Httpd服务入门知识-正向代理和反向代理
Httpd服务入门知识-正向代理和反向代理 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.正向代理和反向代理 启用反向代理 ProxyPass "/" &q ...
- zabbix--CPU监控并告警
zabbix监控CPU超值则报警 由于默认没有 cpu 的使用率监控,需要添加一个监控项,通过 system.cpu.util[,,] 来进行配置 添加监控项 添加图形 添加触发器 展示图
- httprunner学习19-重复执行用例
前言 使用httprunner做接口测试过程中,在工作中会遇到这种场景,发现某个接口不稳定,想重复运行100次用例,甚至1000次,看成功率. yml脚本 - config: name: httpbi ...