在Windows定位的Delphi应用程序中是否对引用的对象进行计数,如果是,则其目的是什么? [英] Are objects reference counted in Windows-targeted Delphi applications, and if so, what is its purpose?

查看:45
本文介绍了在Windows定位的Delphi应用程序中是否对引用的对象进行计数,如果是,则其目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

针对相关问题给出以下答案( https://stackoverflow.com/a/22086392/1420752 )Windows定位的Delphi应用程序中引用的对象计数吗?

Given the following answer to a related question (https://stackoverflow.com/a/22086392/1420752) are objects reference counted in Windows-targeted Delphi applications?

即:

Q1A ,在第二条语句之后,以下对象的引用计数是否为2?

Q1A does the following object have a reference count of 2 after the second statement?

o1 := TMyObject.Create;
o2 := o1;

Q1B 接下来,将 o1 分配给 nil 会将引用计数减为1?

Q1B Following on from the above, will assigning o1 to nil drop the reference count to 1?

o1 := nil;

Q1C 再一次,将 o2 分配给 nil 会将引用计数降至0吗?

Q1C Again following on, will assigning o2 to nil drop the reference count to 0?

o2 := nil;

Q1D 向前看,如果上述方法正确,并且该对象的引用计数现在为0,则我理解编译器将 NOT 自动释放该对象(<为了防止内存泄漏,应该在上面的 o2:= nil 之前调用code> o2.Free .记住,我说的是Windows目标,而不是具有自动引用计数(ARC)的移动目标.

Q1D Moving forward, if the above is correct and the object now has a reference count of 0, I understand that the compiler will NOT automatically free the object (o2.Free should have been called prior to o2 := nil above in order to prevent a memory leak). Remember I'm talking about a Windows target, not a mobile target with automatic reference counting (ARC).

Q1E 如果引用计数不能自动释放与对象关联的内存,那么Delphi中引用计数的精确点是什么(例如,它是否有助于 trace >内存泄漏)?

Q1E If reference counting does not automatically free the memory associated with an object, then what precisely is the point of reference counting in Delphi (e.g., is it to help trace memory leaks)?

推荐答案

在任何桌面平台(包括Windows)下,对象实例都不被引用计数.仅在移动平台(iOS,Android)下对对象进行引用计数.因此,问题Q1A-E尚无定论.

Object instances are not reference counted under any desktop platform, including Windows. Objects are reference counted only under mobile platforms (iOS, Android). So questions Q1A-E are moot.

这篇关于在Windows定位的Delphi应用程序中是否对引用的对象进行计数,如果是,则其目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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