跳到主要内容

· 24 分钟阅读
Ye Shu

我为什么写这篇文章

在我暑期实习期间 debug 一个内存泄漏的问题时,我发现我使用的其中一个 API return 了一个裸指针,从而把这个目标的 ownership 转移给了调用者(我)。换言之,我现在需要负责在代码运行完毕之后手动 delete 掉这个指针。尽管这是一个 非常糟糕的工程实践,我开始对内存泄漏是如何产生的,以及 delete[] 是如何删除内存的产生了兴趣。

在做了一些研究与实验后,我写下了这篇文章。本文将试图回答三组问题:

  1. 什么是内存泄漏?
  2. 对象是如何在 堆 (heap) 上被分配的?delete[] 如何知道它需要释放哪块内存?
  3. 我们如何预防内存泄漏?

· 2 分钟阅读
Ye Shu

My personal website is finally up and running today! It is already 821 days after I purchased this domain (huh I'm such big a procrastinator). I also have a blog running on the subdomain blog.shuye.dev for some longer and possibly non tech-related blog posts.

This is not the first personal website I've ever made. I coded my very first personal website in 2014 using static HTML and CSS (that was the time when most websites were still using HTML 4.01 and you had to decide whether you want a "strict" version of HTML), after a bit of self-learning with W3Schools. In fact, I wasn't even learning from the true W3Schools, but an imitation of it.