PowerBuilder 11.5 和 C# COM 组件的内存问题
首先,对不起我的英语。
我正在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我承认在这种情况下谁拥有内存是模糊的,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.