tealeg / xlsx

Go library for reading and writing XLSX files.
Other
5.88k stars 818 forks source link

Row.PushCell leads to Memory Leak #813

Open liangdy678 opened 3 months ago

liangdy678 commented 3 months ago

Hi, when we merge some xlsx files or copy some cells,memory leak occurs in some application scenarios.

// PushCell adds a predefiend cell to the end of the Row
func (r *Row) PushCell(c *Cell) {
    r.cellStoreRow.Updatable()
    r.isCustom = true  
    r.cellStoreRow.PushCell(c) 
        // c.Row Still only points to the original Row.
        // c.Row -> c.Row.Sheet -> c.Row.Sheet.File , then blocks GC
}

we recommand adding a new function CopyCell

// CopyCell adds a predefiend cell to the end of the Row
func (r *Row) CopyCell(c *Cell) {
    r.cellStoreRow.Updatable()
    r.isCustom = true
        c.Row = r   // Release the reference to the original row,points to the target Row
    r.cellStoreRow.PushCell(c)
}
tealeg commented 2 months ago

@liangdy678 - yes, I see. I hadn't anticipated this use case. I'll consider this for either v4 or the next minor release.

github-actions[bot] commented 5 days ago

Stale issue message