accounting: fix memory leak noticeable for transfers of large numbers of objects

Before this fix we weren't removing transfers from the transfer stats.
For transfers with 1000s of objects this uses a noticeable amount of
memory.

See: https://forum.rclone.org/t/rclone-memory-consumption-increasing-linearly/12244
This commit is contained in:
Nick Craig-Wood 2019-10-15 16:33:09 +01:00
parent 90a23ae01b
commit e337cae0c5
2 changed files with 14 additions and 0 deletions

View File

@ -532,3 +532,16 @@ func (s *StatsInfo) AddTransfer(transfer *Transfer) {
s.startedTransfers = append(s.startedTransfers, transfer)
s.mu.Unlock()
}
// RemoveTransfer removes a reference to the started transfer.
func (s *StatsInfo) RemoveTransfer(transfer *Transfer) {
s.mu.Lock()
for i, tr := range s.startedTransfers {
if tr == transfer {
// remove the found entry
s.startedTransfers = append(s.startedTransfers[:i], s.startedTransfers[i+1:]...)
break
}
}
s.mu.Unlock()
}

View File

@ -113,6 +113,7 @@ func (tr *Transfer) Done(err error) {
} else {
tr.stats.DoneTransferring(tr.remote, err == nil)
}
tr.stats.RemoveTransfer(tr)
}
// Reset allows to switch the Account to another transfer method.