PowerBuilder 11.5 和 C# COM 组件的内存问题

发布于 2024-11-17 19:05:49 字数 809 浏览 3 评论 0原文

首先,对不起我的英语。

我正在 C# 中开发一个 COM 组件(实现 IDisposable),以便从 PowerBuilder 中使用它,如下所示:

OLEObject lole_comComponent

lole_comComponent = Create OLEObject
lole_comComponent.ConnectToNewObject("MyComComponent")

[Do some stuff...]

lole_component.DisconnectObject()
destroy lole_component
GarbageCollect()

使用此代码,关闭应用程序时会触发 COM 组件的析构函数。我已向组件添加了一个调用私有 Dispose 方法的方法。类似这样:

OLEObject lole_comComponent

lole_comComponent = Create OLEObject
lole_comComponent.ConnectToNewObject("MyComComponent")

[Do some stuff...]

lole_component.Close()  // this method calls Dispose(true)
lole_component.DisconnectObject()
destroy lole_component

GarbageCollect()

在这两个示例中,组件使用的内存都没有被释放。

如何释放 COM 组件使用的内存?

我正在使用 PowerBuilder 11.5.1 Build 4740。

First of all, sorry for my english.

I'm developing a COM component in C# (which implements IDisposable) to use it from PowerBuilder something like this:

OLEObject lole_comComponent

lole_comComponent = Create OLEObject
lole_comComponent.ConnectToNewObject("MyComComponent")

[Do some stuff...]

lole_component.DisconnectObject()
destroy lole_component
GarbageCollect()

With this code, destructor of COM Component is triggered when close de app. I've added a method to the component that calls a private Dispose method. Something like this:

OLEObject lole_comComponent

lole_comComponent = Create OLEObject
lole_comComponent.ConnectToNewObject("MyComComponent")

[Do some stuff...]

lole_component.Close()  // this method calls Dispose(true)
lole_component.DisconnectObject()
destroy lole_component

GarbageCollect()

In neither of the two examples the memory used by the component is released.

How I can free the memory used by the COM component?

I'm using PowerBuilder 11.5.1 Build 4740.

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

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

发布评论

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

评论(1

半葬歌 2024-11-24 19:05:49

我承认在这种情况下谁拥有内存是模糊的,PowerBuilder 还是控件,但一个可能有帮助(或没有帮助)的事实是 PowerBuilder 倾向于保留从操作系统分配的内存。理论上,内存请求是性能昂贵的操作,因此它不会经历请求和释放内存的循环(PB 不知道你下一步要做什么),它只是挂在它已请求的内存上,并且不会现在就需要。

HTH,

特里。

I'll confess to being fuzzy on who is owning the memory in this situation, PowerBuilder or the control, but one fact that may be helpful (or not) is the fact that PowerBuilder tends to hang on to memory it gets allocated from the OS. The theory is that memory requests are performance expensive operations, so instead of going through cycles of requesting and releasing memory (PB doesn't know what you're going to do next), it just hangs onto memory it has requested and doesn't need right now.

HTH,

Terry.

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