You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As the title says, using a struct schema which has circular links (as can happen using an ORM like GORM), the memory usage explodes and the program is killed. I have created a small repo with the minimal code to reproduce the issue. I have also attached some code directly below. https://github.com/SetorHabona/gocsv-mem-leak
NOTE: An easy fix is excluding the inner struct using csv:"-"
package main
import (
"fmt""os""github.com/gocarina/gocsv"
)
// this setup is not not very unusual when working with gorm (maybe also other ORMs)typeWrapperstruct {
Namestring`csv:"name"`Ageuint`csv:"age"`// Inner creates a problem, both as pointer and as valueInner*Inner// add `csv:"-"` to avoid rapid increase in consumed memory and your program being killed
}
typeInnerstruct {
PositionstringSalaryuintWrappers*Wrapper
}
funcmain() {
file, err:=os.OpenFile("./data.csv", os.O_RDWR|os.O_CREATE, os.ModePerm)
iferr!=nil {
panic(err)
}
deferfile.Close()
varwraps []Wrapperiferr:=gocsv.UnmarshalFile(file, &wraps); err!=nil {
panic(err)
}
fmt.Printf("%+v\n", wraps)
}
The text was updated successfully, but these errors were encountered:
As the title says, using a struct schema which has circular links (as can happen using an ORM like GORM), the memory usage explodes and the program is killed. I have created a small repo with the minimal code to reproduce the issue. I have also attached some code directly below. https://github.com/SetorHabona/gocsv-mem-leak
NOTE: An easy fix is excluding the inner struct using
csv:"-"
The text was updated successfully, but these errors were encountered: