Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible memory leak? #76

Open
theothertomelliott opened this issue May 12, 2019 · 0 comments
Open

Possible memory leak? #76

theothertomelliott opened this issue May 12, 2019 · 0 comments

Comments

@theothertomelliott
Copy link

I've been using go-libsass to compile sass content for static sites in a long-running process, and believe I'm seeing a memory leak in the library.

I put together a small program to exercise this:

package main

import (
	"fmt"
	"io/ioutil"
	"log"
	"runtime"
	"strings"
	"time"

	humanize "github.com/dustin/go-humanize"
	libsass "github.com/wellington/go-libsass"
)

func main() {
	var (
		sample = `
$font-stack:    Helvetica, sans-serif;
$primary-color: #333;
body {
	font: 100% $font-stack;
	color: $primary-color;
}
		`
		maxAlloc uint64
		start    = time.Now()
	)
	for i := 0; true; i++ {
		comp, err := libsass.New(ioutil.Discard, strings.NewReader(sample))
		if err != nil {
			log.Fatal(err)
		}

		if err := comp.Run(); err != nil {
			log.Fatal(err)
		}
		var m runtime.MemStats
		runtime.ReadMemStats(&m)
		if m.Alloc > maxAlloc*2 {
			maxAlloc = m.Alloc
			fmt.Printf(
				"%v (%d): Alloc = %v MiB, NumGC = %v\n",
				time.Since(start),
				i,
				humanize.Bytes(maxAlloc),
				m.NumGC,
			)
		}
	}
}

Running using go-libsass v0.9.2 I see the following output after running for 10 minutes:

1.839078ms (0): Alloc = 106 kB MiB, NumGC = 0
21.184192ms (26): Alloc = 215 kB MiB, NumGC = 0
55.547495ms (79): Alloc = 432 kB MiB, NumGC = 0
109.932748ms (186): Alloc = 868 kB MiB, NumGC = 0
206.257662ms (400): Alloc = 1.7 MB MiB, NumGC = 0
713.857603ms (1563): Alloc = 3.5 MB MiB, NumGC = 1
4.377593582s (9946): Alloc = 7.0 MB MiB, NumGC = 16
8.849047488s (19345): Alloc = 14 MB MiB, NumGC = 24
22.658077622s (40564): Alloc = 28 MB MiB, NumGC = 33
46.552797916s (78313): Alloc = 56 MB MiB, NumGC = 41
1m38.739205546s (165444): Alloc = 111 MB MiB, NumGC = 50
2m59.728412134s (318347): Alloc = 223 MB MiB, NumGC = 58
6m5.303138905s (660328): Alloc = 446 MB MiB, NumGC = 67

Is there a step I'm missing to release resources? Or is there something that needs adding to the Run() function?

@theothertomelliott theothertomelliott changed the title Possibly memory leak? Possible memory leak? May 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant