NetCoreServer icon indicating copy to clipboard operation
NetCoreServer copied to clipboard

内存占用

Open WangYou77 opened this issue 1 year ago • 3 comments

是不是缺少释放内存,当并发量跟请求体过大,应用占用的内存会居高不下

WangYou77 avatar Dec 12 '24 02:12 WangYou77

以TcpSession为例,是不是缺少一个Flush方法

WangYou77 avatar Dec 12 '24 02:12 WangYou77

我看了源代码,断开后注销Session代码 如下,

        /// <summary>
        /// Unregister session by Id
        /// </summary>
        /// <param name="id">Session Id</param>
        internal void UnregisterSession(Guid id)
        {
            // Unregister session by Id
            Sessions.TryRemove(id, out TcpSession _);
        }

按你说的没有释放 ,可以改成

        /// <summary>
        /// Unregister session by Id
        /// </summary>
        /// <param name="id">Session Id</param>
        internal void UnregisterSession(Guid id)
        {
            // Unregister session by Id
            Sessions.TryRemove(id, out TcpSession tcpSession);
            if (tcpSession!=null) {
                if (tcpSession.IsDisposed == false) {
                    tcpSession.Dispose();
                }
                tcpSession = null;
            }
        }

toolgood avatar Feb 17 '25 06:02 toolgood

还有一点可以减少内存,使用int 代码long ,int占用4个byte,long占用8个byte。而且使用tcp传输文件也不会超800M,足够用了

toolgood avatar Mar 03 '25 12:03 toolgood