Is there a non-reference-counted base class like TInterfacedObject?

前端 未结 5 1270
无人及你
无人及你 2021-02-07 08:47

I need a base class like TInterfacedObject but without reference counting (so a kind of TNonRefCountedInterfacedObject).

This actually is the

5条回答
  •  生来不讨喜
    2021-02-07 09:25

    There is no such class, but you can easily write your own, as others have shown. I do, however, wonder why you would need it. In my experience, there is seldom a real need for such a class, even if you want to mix object and interface references.

    Also note that when you use such a class, you'll still have to take care of setting any interface references you have to such an object to nil before they leave scope and before you free the object. Otherwise you might get the situation the runtime tries to call _Release on a freed object, and that tends to cause an invalid pointer exception.

    IOW, I would advise against using such a class at all.

提交回复
热议问题