Delphi自动垃圾收集器

发布于 2024-09-28 15:07:31 字数 418 浏览 2 评论 0原文

是否有可能考虑将来在Delphi中拥有一个自动垃圾收集器?在许多应用程序中,对何时释放对象进行高度详细的控制并不那么重要,这只是需要额外关心的事情。

对于这样的应用程序来说,拥有一种像 java 的垃圾收集器一样工作的垃圾收集器会很有趣。

可以在项目选项中设置。

这可能吗?

注意:我并不是要像解释的那样手动创建它此处,我真正指的是 Delphi 功能。

换句话说:是否可以将FastMM设置为垃圾收集器?

Is it possible to think to have in future an automatic garbage collector in Delphi? There are many applications in which a higly detailed control on when to free an object is not so important and it is just an extra thing to care about.

For such applications having a kind of garbage collector that works like java's one would be interesting.

It could be set in the project options.

Will this possible or not?

Note: I don't mean to manually create it like explained here, I really mean a Delphi feature.

Stated in another way: is it possible to set FastMM to act as Garbage collector?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

梦境 2024-10-05 15:07:31

C 和 C++ 中可以进行垃圾回收,所以我认为 Delphi 没有理由不能也有这样的功能。如果您祈祷并等待足够长的时间,Delphi 可能会进行垃圾收集。不过,我并不认为这是内河码头的首要任务。

您无法将 FastMM 设置为垃圾收集器,因为 FastMM 不执行垃圾收集,因此无需设置任何内容。 Delphi 假设的未来垃圾收集功能可能必须与内存管理器配合,因此如果这样的功能曾经存在,并且当时 FastMM 仍然是内存管理器,那么 FastMM 可能会获得一些设置。

Garbage collection is possible in C and C++, so I see no reason why Delphi couldn't also have such a feature. If you cross your fingers and wait long enough, Delphi might get garbage collection. I don't see it as a priority for Embarcadero, though.

You can't set FastMM to act as a garbage collector because FastMM doesn't do garbage collection, so there's nothing to set. Delphi's hypothetical future garbage-collection feature would probably have to cooperate with the memory manager, so if such a feature ever exists, and FastMM is still the memory manager at that time, then FastMM will probably gain some settings.

独孤求败 2024-10-05 15:07:31

在许多应用程序中,对何时释放对象进行高度详细的控制并不那么重要,这只是需要额外关心的事情。

我相信几乎没有这样的应用程序。大多数时候,您认为不需要控制对象何时被销毁,那么您可能会引入错误。

现在,确实在某些情况下可以安全地忽略某些对象,以便稍后由自动收集器处理。但请记住,对于您计划不手动销毁的每个对象,您都需要仔细考虑这一点。如果它持有一些锁怎么办?如果它打开了一些文件(可能处于拒绝共享模式)怎么办?

让您不再考虑销毁每个对象并没有多大好处,当安全地编程时您仍然需要考虑销毁每个对象。

垃圾收集器的目的不是让程序员看清这些东西。这是为了节省一点引用计数和 try/finally 调用。

There are many applications in which a higly detailed control on when to free an object is not so important and it is just an extra thing to care about.

I believe there are almost none such applications. Most of the times you think you don't require a control on when your objects are destroyed, you're potentially introducing a bug.

Now, there indeed are cases when certain objects can be safely ignored to later be dealt with by automatic collector. But keep in mind that you need to think this through for every object you're planning on not destroying manually. What if it holds some locks? What if it has some files open, maybe in share-deny mode?

There's not much of a benefit in freeing you from thinking about destroying every object, when to program safely you still need to think about destroying every object.

The purpose of garbage collectors is not to free programmers from seeing this stuff through. It's to save a bit on reference counting and try/finally calls.

萌化 2024-10-05 15:07:31

垃圾收集既有优点也有缺点,我认为即使没有 GC(垃圾收集器),delphi 也很好。即使delphi应用程序占用的内存大小比托管.net应用程序少,有时垃圾收集也会减慢进程,因为它必须找到不需要的资源,确认它们是否再次需要并删除它。如果再次需要它必须再次加载(应用程序变得很慢)或者出现错误,所以 delphi 很好,无需 GC 手动释放对于专业程序员来说是有好处的

you have both pros and cons with garbage collection i thing delphi is good even without GC(garbage collector). even delphi apps take less memory size than managed .net apps , some times garbage collection also slow down the process because it has to find the unwanted resources , confirm whether they are needed again and delete it.if it needed again it has to load again( app becomes slow) or an error there so delphi is good without GC manually freeing is good for a professional programmer

荒岛晴空 2024-10-05 15:07:31

Delphi 的最新版本带有 RTTI(这也是应用程序体积较大的原因)
我认为 rtti(运行时类型信息)可以在未来帮助我们。因为它保存了有关正在进行的过程的一些信息,所以我认为将来可能会出现一些类似的功能,例如垃圾收集器,但不确定

lasted versions of delphi coming with RTTI (this is also a reason for the big size of apps)
i think rtti(Runtime Type Information) can help us in future . because it hold some informations about the process going on so i think may be in future some similar function like garbage collector is possible but not sure

别靠近我心 2024-10-05 15:07:31

但是 delphi for dot net 2007 和其他旧的 delphi dot net 有垃圾收集器 + vcl 但现在已弃用(垃圾收集器也不能 100% 正常工作)

but delphi for dot net 2007 and other old delphi dot net have garbage collector + vcl but now deprecated (the garbage collector also dont work 100% well)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文