-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Streamwriter Memory Leak #1760
Comments
Thanks for your issue. If you print gc traces by embedding gctrace env package main
import (
"fmt"
"math/rand"
"runtime"
"github.com/xuri/excelize/v2"
)
func main() {
for i := 0; i < 5; i++ {
f := excelize.NewFile()
sw, err := f.NewStreamWriter("Sheet1")
if err != nil {
fmt.Println(err)
return
}
for rowID := 1; rowID <= 102400; rowID++ {
row := make([]interface{}, 50)
for colID := 0; colID < 50; colID++ {
row[colID] = rand.Intn(640000)
}
cell, err := excelize.CoordinatesToCellName(1, rowID)
if err != nil {
fmt.Println(err)
break
}
if err := sw.SetRow(cell, row); err != nil {
fmt.Println(err)
break
}
}
if err := sw.Flush(); err != nil {
fmt.Println(err)
return
}
if err := f.SaveAs("Book1.xlsx"); err != nil {
fmt.Println(err)
}
if err := f.Close(); err != nil {
fmt.Println(err)
}
fmt.Printf("[%d] GC ...\r\n", i)
runtime.GC()
fmt.Printf("[%d] GC Done\r\n", i)
}
} You can see something like this:
The heap size at GC starts from 35MB to 3MB at GC end on each garbage collection, the memory was not leaked. You can also observe the GC in other ways, such as go tool trace and print the memory by runtime.ReadMemStats, etc. So I've closed this issue, if you have any questions please let me know, and you can reopen this anytime. |
Description
![image](https://private-user-images.githubusercontent.com/144706161/290950443-1a8a9dd8-3533-4d23-a76a-00ea3ec96643.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjA2MzE0NTksIm5iZiI6MTcyMDYzMTE1OSwicGF0aCI6Ii8xNDQ3MDYxNjEvMjkwOTUwNDQzLTFhOGE5ZGQ4LTM1MzMtNGQyMy1hNzZhLTAwZWEzZWM5NjY0My5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNzEwJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDcxMFQxNzA1NTlaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT00OWU4MjE0ZjUwYzQ0YmEwNWQxYzk4ODI4ZjBhMjgzNTYyYzQyZTEzNzEzNzNkMzM2NWRiNDFhMjVlNDNmNTQ0JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.MP7-0j7pjcIn0ApJvV38PjYuay47s5YEuQVttfPTnTk)
Using Streamwriter to convert large JSON arrays into XLSX (50k+ rows). At the end of the function, Streamwriter.Flush() & runtime.GC() is called, manually freeing a lot of allocated memory, but nothing from Streamwriter. Streamwriter will either hog large amounts of memory for minutes at a time, or not release it.
Steps to reproduce the issue:
Describe the results you received:
Memory leak from excelize
Describe the results you expected:
Memory released
Output of
go version
:Excelize version or commit ID:
Environment details (OS, Microsoft Excel™ version, physical, etc.):
Linux kernel 5.15.0-88-generic
The text was updated successfully, but these errors were encountered: