Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/slimsag/darfree
Uses black magic to release memory on Darwin.
https://github.com/slimsag/darfree
2017 black darfree dontuse go golang lower magic memory normal pleasedonotuse seriously than trending usage
Last synced: about 1 month ago
JSON representation
Uses black magic to release memory on Darwin.
- Host: GitHub
- URL: https://github.com/slimsag/darfree
- Owner: slimsag
- Created: 2017-06-13T05:41:50.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-06-13T05:42:45.000Z (over 7 years ago)
- Last Synced: 2024-10-30T18:48:35.338Z (3 months ago)
- Topics: 2017, black, darfree, dontuse, go, golang, lower, magic, memory, normal, pleasedonotuse, seriously, than, trending, usage
- Language: Go
- Size: 2.93 KB
- Stars: 2
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Package darfree uses black magic to release memory on Darwin.
darfree is a package that uses ⚫️ black magic (assembly and runtime monkey
patching) to lower the perceived memory consumption of Go programs on
Darwin / amd64 (Mac OS) systems. Since it is based on page size, the actual
'gains' are dependent upon the program itself. They can be as much as your
largest heap allocation. See cmd/darfree for an example which uses ~500MB
without darfree, and only ~17MB with.## Background
Go allocates memory in pages, and later advises the operating system that it
may free unneeded memory using madvise(..., MADV_FREE) calls. On Linux, this
system call immediately frees the memory page. However, on Darwin machines
the kernel will decide to retain that memory as part of your program's RSS
(residential set size) until memory pressure by your application or another
running on the system causes the kernel to _truly_ free that memory.
In reality, Darwin does the right thing. Keeping the memory as part of your
program's RSS causes no harm, and actually benefits your program by making
subsequent allocations faster. However, from a user's perspective looking at
their "Activity Monitor" it will look like your application is leaking or
using much more memory than it actually is. That is what darfree solves.## Beware
I advise you really do not use this package at all, unless you really
understand what is going on and what the trade-offs are. At any point in
time this package may become unmaintained, and may break with future Go
versions.## Usage
```Go
package mainimport _ "github.com/slimsag/darfree"
func main() {
// ...
}
```