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)内存上分辨哪些对象还在被使用,哪些对象没有被使用,并清除没有被使用的对象.所以,这里的垃 ...
随机推荐
- 链接标签(a 标签)
一.链接标签 单词缩写: anchor 的缩写. 在HTML中创建超链接非常简单,只需用标签环绕需要被链接的对象即可. 语法格式: <a href="跳转目标" target ...
- 地产propretie单词propretie财产
中文名:房产财产地产 外文名:property.propretie 释义:财产.所有物等 用法:作名词. 词汇搭配动词+-等 目录 1 英文释义 2 释义例句 3 词汇搭配 4 衍生 英文释义 1. ...
- Android中控件AutoCompleteTextView的使用方法和一些属性
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...
- springboot-发布jar包
其他参考链接: https://www.cnblogs.com/blog5277/p/5920560.html 环境变量配置: 新建系统变量MAVEN_HOME: 在path中添加: ;%MAVEN_ ...
- MySQL数据库中字符串函数之left、right用法
语法 LEFT(str,len) Returns the leftmost len characters from the string str, or NULL if any argument is ...
- uboot是什么
u-boot是一种普遍用于嵌入式系统中的Bootloader,Bootloader是在操作系统运行之前执行的一小段程序,通过它,我们可以初始化硬件设备.建立内存空间的映射表,从而建立适当的软硬件环境, ...
- Httpd服务入门知识-Httpd服务常见配置案例之DSO( Dynamic Shared Object)加载动态模块配置
Httpd服务入门知识-Httpd服务常见配置案例之DSO( Dynamic Shared Object)加载动态模块配置 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.加载动 ...
- LVS负载均衡部署
一.lvs-nat模式 1.1.环境介绍 本实验用三台虚拟机完成,一台虚拟机模拟lvs调度器,两块网卡,一块模拟公网一块模拟私网,公网地址192.168.0.201/24,私网地址192.168.4. ...
- 卓越Code团队SCRUM呕心沥血实践总结
卓越Code团队SCRUM呕心沥血实践总结 序言 所属课程 https://edu.cnblogs.com/campus/xnsy/2019autumnsystemanalysisanddesign ...
- 矩阵LU分解程序实现(Matlab)
n=4;%确定需要LU分解的矩阵维数 %A=zeros(n,n); L=eye(n,n);P=eye(n,n);U=zeros(n,n);%初始化矩阵 tempU=zeros(1,n);tempP=z ...