什么是锈迹策略,以免记忆并将内存返回操作系统?
在堆上分配内存是一个昂贵的操作,因此,即使不再使用分配的内存,有些编程语言避免将其归还操作系统。
但是对于许多情况,例如在云上运行的微服务,您希望拥有较低的内存使用情况,否则该帐单可能很高。 因此,在这些情况下,在不使用内存后释放它确实很重要。
什么是RUST默认策略,以免分配并将内存返回操作系统?
如何改变?
Allocate memory on heap is an expensive operation and so some programming languages avoid to give it back to the operating system, even if the allocated memory is not being used anymore.
But for many scenarios, for example microservices running on cloud, you would to like to have low memory usage, otherwise the bill can be quite high.
So in these cases it's really important to release the memory after it is not being used.
What is Rust default strategy to uncommit and return memory to the operating system?
How can that be changed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,RUST使用系统分配器。
调用
free()
是否实际上使其他进程的内存取决于LIBC实现和您的操作系统,并且该问题主要与生锈无关(请参见下面的链接)。无论如何,释放的内存都应用于将来的分配,因此长期运行的过程不会泄漏内存。我的一般经验是,Rust服务器的资源消耗非常低。
另请参见:
By default Rust uses the system allocator.
Whether calling
free()
actually makes the memory available to other processes depends on the libc implementation and your operating system, and that question is mostly unrelated to Rust (see the links below). In any case, memory that was freed should be available for future allocations, so long-running processes don't leak memory.My general experience is that resource consumption of Rust servers is very low.
See also: