-
Notifications
You must be signed in to change notification settings - Fork 7
/
README
39 lines (25 loc) · 1.25 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
NOTE: As of Go 1.23, memsize no longer works because of a restriction added by the
Go toolchain. The Go 1.23 compiler no longer allows access to runtime symbols via
go:linkname, which prevents memsize from accessing the Stop-the-World
functionality of the Go runtime.
If your program depends on memsize, you can disable the restriction when building
your program:
go build -ldflags=-checklinkname=0
---
For Go API documentation, go to https://pkg.go.dev/github.com/fjl/memsize
---
Package memsize computes the size of your object graph.
For any Go object, it can compute the amount of memory referenced by the object.
Almost all Go types are supported, except for function pointers.
To scan a value and print the amount of memory it uses, run
sizes := memsize.Scan(myValue)
fmt.Println(sizes.Total)
If your program provides an HTTP server for debugging (e.g. using net/http/pprof),
you can also add an interactive memsize tool there and use it from a
web browser. To do this, add
import "github.com/fjl/memsize/memsizeui"
var memsizeH memsizeui.Handler
and then hook the handler up to your debugging HTTP server. The web
interface will display buttons for added 'roots', which you must register
on the handler:
memsizeH.Add("myObject", &myObject)