Coder Social home page Coder Social logo

关于内存的释放问题 about uv-cpp HOT 5 CLOSED

wlgq2 avatar wlgq2 commented on August 23, 2024
关于内存的释放问题

from uv-cpp.

Comments (5)

wlgq2 avatar wlgq2 commented on August 23, 2024

https://github.com/wlgq2/uv-cpp/tree/master/examples/server_quit
你可以试试这个例程,我之前win/debian下测试过。如果内存一直增大,可以反馈。

from uv-cpp.

yandaomin avatar yandaomin commented on August 23, 2024

可能我没有说太清楚,是这样的场景,我在ubuntu20.04下启动server,这时server占的内存不到1m;
然后我在windows下启动1000个client并连接到 server端,然后每隔一秒每个客户端发送1条消息给server端;
我观察server的内存这时为64m左右,然后关闭所有客户端,但server端的内存仍然维持在64M(但在windows下内存是会下来的);同样,如果我连接1万左右客户端且每秒每个客户端1条消息,内容约占640M左右,然后我关闭所有客户端,server的内存没有降下来一直在640m左右,当然,后续我又连接1000客户端上去并每秒每个客户端发送一条消息,此时server端内容并没有涨,仍然是640M左右;所以,我的疑问是同样的代码在windows和linux下的表现不一样,windows是客户端断开后立即释放内存,而linux下是不会释放内存(而且再连接客户端上来也不会涨,除非超过了server之前的最大内存,例如:连接12000客户端,server端内存会变为 640M + 128M左右)。
所以, 我想了解一下为什么 会产生这样的现象?

from uv-cpp.

wlgq2 avatar wlgq2 commented on August 23, 2024

@yandaomin
可能和操作系统及编译器的内存管理策略有关,Delete 只是标记这块内存可用,不会清除内容。
如果你反复连接1000个客户端,断开。内存没有持续增长,是没有内存泄漏的。
程序中没有缓存池机制,释放后内存不降低可能 和操作系统及编译器的内存管理机制有关。

from uv-cpp.

wlgq2 avatar wlgq2 commented on August 23, 2024

你可以测试在你的编译环境中 new 100M的大数组,在释放掉,看看程序占用内存有没有降低。
https://bbs.csdn.net/topics/392510730 可以参考下

from uv-cpp.

yandaomin avatar yandaomin commented on August 23, 2024

了解了,感谢 :)

from uv-cpp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.