在使用workflow4时,循环调用1000次workflow,内存会一直增长,直到提示内存不足。
我使用微软的例子测试也有这样的问题。
请问是什么原因呢?
工作流应该如何释放内存呢?
内存没有被释放,建议把代码贴出来看看
谢谢!请问WF4中如何释放内存呢?
下面是我的部分代码,就是客户端调用WCF服务端的GetData方法100次,GetData方法只返回一个result,值为"true"的字符串:
基于WCF的WF代码:
<WorkflowService mc:Ignorable="sap" ConfigurationName="Service1" sap:VirtualizedContainerService.HintSize="309,382" Name="Service1" mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces" xmlns="http://schemas.microsoft.com/netfx/2009/xaml/servicemodel" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mv="clr-namespace:Microsoft.VisualBasic;assembly=System" xmlns:mva="clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities" xmlns:p="http://tempuri.org/" xmlns:p1="http://schemas.microsoft.com/netfx/2009/xaml/activities" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:s1="clr-namespace:System;assembly=System" xmlns:s2="clr-namespace:System;assembly=System.Xml" xmlns:s3="clr-namespace:System;assembly=System.Core" xmlns:sad="clr-namespace:System.Activities.Debugger;assembly=System.Activities" xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation" xmlns:scg="clr-namespace:System.Collections.Generic;assembly=System" xmlns:scg1="clr-namespace:System.Collections.Generic;assembly=System.ServiceModel" xmlns:scg2="clr-namespace:System.Collections.Generic;assembly=System.Core" xmlns:scg3="clr-namespace:System.Collections.Generic;assembly=mscorlib" xmlns:sd="clr-namespace:System.Data;assembly=System.Data" xmlns:sl="clr-namespace:System.Linq;assembly=System.Core" xmlns:st="clr-namespace:System.Text;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<p1:Sequence DisplayName="Sequential Service" sad:XamlDebuggerXmlReader.FileName="D:\源代码\WFMemoryTest\WfServer\WfServer\Service1.xamlx" sap:VirtualizedContainerService.HintSize="279,352" mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces">
<p1:Sequence.Variables>
<p1:Variable x:TypeArguments="CorrelationHandle" Name="handle" />
<p1:Variable x:TypeArguments="x:Int32" Name="data" />
</p1:Sequence.Variables>
<sap:WorkflowViewStateService.ViewState>
<scg3:Dictionary x:TypeArguments="x:String, x:Object">
<x:Boolean x:Key="IsExpanded">True</x:Boolean>
</scg3:Dictionary>
</sap:WorkflowViewStateService.ViewState>
<Receive x:Name="__ReferenceID0" CanCreateInstance="True" DisplayName="ReceiveRequest" sap:VirtualizedContainerService.HintSize="257,94" OperationName="GetData" ServiceContractName="p:IService">
<Receive.CorrelationInitializers>
<RequestReplyCorrelationInitializer CorrelationHandle="[handle]" />
</Receive.CorrelationInitializers>
</Receive>
<SendReply Request="{x:Reference __ReferenceID0}" DisplayName="SendResponse" sap:VirtualizedContainerService.HintSize="257,94">
<SendParametersContent>
<p1:InArgument x:TypeArguments="x:String" x:Key="result">true</p1:InArgument>
</SendParametersContent>
</SendReply>
</p1:Sequence>
</WorkflowService>
Web.config配置:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.web> <compilation debug="true" targetFramework="4.0" /> </system.web> <system.serviceModel> <behaviors> <serviceBehaviors> <behavior> <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> <serviceMetadata httpGetEnabled="true"/> <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> <serviceDebug includeExceptionDetailInFaults="false"/>
<sqlWorkflowInstanceStore connectionString="××××××××××"/> <!--Set the TimeToUnload to 0 to force the WF to be unloaded. To have a durable delay, the WF needs to be unloaded otherwise it will be thread as an in-memory delay--> <workflowIdle timeToUnload="0"/> </behavior> </serviceBehaviors> </behaviors> <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> </system.serviceModel> <system.webServer> <modules runAllManagedModulesForAllRequests="true"/> </system.webServer> </configuration>
客户端调用:
ServiceReference1.ServiceClient client = new ServiceReference1.ServiceClient();
for (int i = 0; i <= 100; i++)
{
string result = client.GetData();
}
按你这代码 不应该这样啊。。