【发布时间】:2016-08-31 11:19:44
【问题描述】:
我有一个问题:
-
我创建了一个默认的 ServiceReference
[OperationContract] string GetData(int value);实施:
public string GetData(int value) { return string.Format("You entered: {0}", value); } 将 ServiceReference 添加到新的 UWP 项目中 (Add Reference Pic.)
-
在我调用的 UWP 主构造函数中:
void Test() { ServiceReference.Service1Client h = new ServiceReference.Service1Client(); for (int i = 0; i < 10000; i++) { var u = h.GetDataAsync(5); } }或者:
async void Test() { ServiceReference.Service1Client h = new ServiceReference.Service1Client(); for (int i = 0; i < 10000; i++) { var u = await h.GetDataAsync(5); } } -
问题: WCF 服务有效。 UWP 应用程序有效。但是进程内存永远不会减少。 Memory Pic. 垃圾收集器什么也不做。
当我打电话时:
GC.Collect(2); GC.WaitForPendingFinalizers();它改变“无”(没有上升那么多)。但是进程内存永远不会减少。
在内存不足的设备上,当内存已满时,应用程序将崩溃。(树莓派 2 / 3)。
我做错了什么。
Raspberry pi 2 / 3 场景:应用程序在日常循环中调用 ServiceReference。该应用程序全年运行。有时应用程序会因为内存已满而崩溃。
【问题讨论】:
-
您只发布了部分代码,但没有遗漏 dispose 或将您的客户端放入 using 块中?
-
ServiceReference 没有 dispose 函数。在 Using-Block 中只能使用 IDisposable 对象。
标签: c# visual-studio wcf memory-leaks garbage-collection