go-libreofficekit icon indicating copy to clipboard operation
go-libreofficekit copied to clipboard

Unfreed memory usage

Open cork opened this issue 5 years ago • 0 comments

I have a problem where i push hundreds of .fodt => .pdf files through this loop and get a ~.5MiB extra memory usage per file and it is not feed (so not gc). Moving office into the loop explodes the memory usage over time so i'm out of ides. Am i doing something wrong here or is something related to the document not freed on doc.Close()?

type Request struct {
	SourceFile string
	TargetFile string
	TargetExt  string
	Filter     string
	done       chan bool
}

var request chan *Request

func office() {
	office, err := libreofficekit.NewOffice("/usr/lib/libreoffice/program")
	if err != nil {
		log.Fatal(err)
	}
	defer office.Close()

	for {
		select {
		case r := <-request:
			doc, err := office.LoadDocument(r.SourceFile)
			if err != nil {
				office.GetError()
				r.done <- true
				continue
			}
			defer doc.close()

			if err := doc.SaveAs(r.TargetFile, r.TargetExt, r.Filter); err != nil {
				r.done <- true
				continue
			}

			r.done <- true
		}
	}
}

cork avatar Jan 07 '20 15:01 cork