NewLife/NewLife.Remoting

响应结果可能是 IOwnerPacket,需要释放资源,把缓冲区还给池
智能大石头 authored at 2024-12-16 23:43:52
6b16228
Tree
1 Parent(s) 0e000bf
Summary: 1 changed files with 4 additions and 1 deletions.
Modified +4 -1
Modified +4 -1
diff --git a/NewLife.Remoting/ApiServer.cs b/NewLife.Remoting/ApiServer.cs
index 0952ac1..6f72896 100644
--- a/NewLife.Remoting/ApiServer.cs
+++ b/NewLife.Remoting/ApiServer.cs
@@ -234,9 +234,9 @@ public class ApiServer : ApiHost, IServer
         var code = 0;
         var st = StatProcess;
         var sw = st.StartCount();
+        Object? result = null;
         try
         {
-            Object? result;
             try
             {
                 Received?.Invoke(this, new ApiReceivedEventArgs { Session = session, Message = msg, ApiMessage = request });
@@ -284,6 +284,9 @@ public class ApiServer : ApiHost, IServer
         {
             var msCost = st.StopCount(sw) / 1000;
             if (SlowTrace > 0 && msCost >= SlowTrace) WriteLog($"慢处理[{request?.Action}],Code={code},耗时{msCost:n0}ms");
+
+            // 响应结果可能是 IOwnerPacket,需要释放资源,把缓冲区还给池
+            result.TryDispose();
         }
     }