垃圾收集与非垃圾回收的编程语言 [英] Garbage collection vs. non garbage collection programming languages

查看:400
本文介绍了垃圾收集与非垃圾回收的编程语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,如果我理解不错,垃圾收集会自动回收未使用的程序了对象。像Java中的垃圾收集器。

So if I understand well, Garbage collection automatically deallocates objects that are not used by the program anymore. like the garbage collector in java.

我听到像C不支持垃圾回收程序可以有内存泄漏,随后耗尽内存的语言。

I hear in languages like C that don't support garbage collection the programs can have memory leaks and subsequently exhaust the memory.

那么,什么是错误的程序员,使像C不支持垃圾收集的语言吗?我猜后,他们不再使用不解除分配的对象。但这些唯一的错误,我们可以因为缺乏垃圾收集的?

So what are the errors that programmer make in languages like C that don't support garbage collection? I would guess not deallocating objects after they're not used anymore. But are these the only errors that we can make because of the lack of a garbage collector?

推荐答案


  • Dellocating事情你需要

  • Dellocating things you need

    不重新分配的东西,你不再需要(因为你不跟踪分配/使用/释放以及)

    Not deallocating things you no longer need (because you're not tracking allocations/use/frees well)

    重新分配了已存在的

    去分配你已经释放的东西

    De-allocating something you've already freed

    去分配的东西不存在(一个空指针)

    De-allocating something that doesn't exist (a null pointer)

    有可能更多。问题的关键是:管理内存是棘手的,并使用某种形式的跟踪机制和分配/释放抽象最好的处理。因此,你可能也有一个内置到语言,因此它可以使好和您轻松。手册内存管理是不是世界的尽头 - 这肯定是可行的 - 但这些天,除非你正在编写实时code,硬件驱动程序,或(或许,可能)超优化的核心$最新的游戏的C $ C,然后手动努力是不值得的,除了学术活动。

    There are probably more. The point is: managing memory is tricky, and is best dealt with using some sort of tracking mechanism and allocating/freeing abstraction. As such, you might as well have that built into your language, so it can make it nice and easy for you. Manual memory management isn't the end of the world -- it's certainly doable -- but these days, unless you're writing real-time code, hardware drivers, or (maybe, possibly) the ultra-optimised core code of the latest game, then manual effort isn't worth it, except as an academic exercise.

    这篇关于垃圾收集与非垃圾回收的编程语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆