-
Notifications
You must be signed in to change notification settings - Fork 480
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cache: use finalizer for freeing manually allocated memory
Currently, the `entryCacheAlloc` struct maintains a slice of `entry` structs. When CGo is enabled, the latter is backed by manually allocated memory. As the former is a pooled struct, when it is released from the pool, it will be garbage collected by the Go runtime. The patch in #1087 introduced a regression where a no-op finalizer is used unless running with `invariants` or `trace` when `race` is disabled. Typical production binaries will not have these flags set, so the no-op finalizer is installed in place of a "real" finalizer. This results in a small memory leak given that the memory backing each of the `entry` items is not released when the pool releases an `entryCacheAlloc` and it is garbage collected by the runtime. Revert to installing the "real" finalizer in this case, as it is required for correctness. Update the documentation on the use of finalizers to point out that we do indeed rely on them for correctness, in a very niche, but valid usecase for freeing manually allocated memory. Fixes #1588.
- Loading branch information
Showing
3 changed files
with
52 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters