简单跨应用程序对象中的内存泄漏
我正在尝试跨 AppDomain 对象,发现了一件很奇怪的事情。
当我调用一个远程方法时,该方法分配一个 MemoryStream 对象并返回它的引用(并且由调用者立即处理),即使在调用 GC.Collect() 之后,内存使用量也会显着增加并且不会下降。
在每次返回new String或byte[]对象的调用方法上,不存在泄漏。
内存分析器显示大多数活动对象都是 Char[] 和 String 类型(对于 MemoryStream)。
问题是 - 我是否误解了什么,远程调用并不像从 MarshalByRefObject 继承那么简单?
I am experimenting with cross-AppDomain objects, and found one quite strange thing.
When I call a remote method, which is allocating a MemoryStream object and returning it's reference (and which is immediately disposed by the caller), memory usage is quite significantly increasing and is not dropping down, even after calling GC.Collect().
On the calling method which returns new String or byte[] object every time, there is no leak.
The Memory profiler shows that most live objects are of type Char[] and String (in case of MemoryStream).
The question is - did I misunderstand something, and remote calls are not so simple as inheriting from MarshalByRefObject?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
远程调用同样简单 - 但对象生存期和垃圾收集就没那么简单了。
您应该阅读一些 租赁和赞助。
Remote calls are as easy - but object lifetime and garbage collection are not as simple.
You should read a bit on leases and sponsorships.