Skip to content

Commit 2435da1

Browse files
committed
Dereference for GC
1 parent 8cb9f82 commit 2435da1

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

batch.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ func (b *Batch) Push(record interface{}) error {
4646
if err := b.pushHandler(batch); err != nil {
4747
return err
4848
}
49+
50+
// dereference batch to clue GC, unless user wants to retain data
51+
batch = nil
4952
} else {
5053
b.itemsToSave[b.batchPosition] = record
5154
b.batchPosition++
@@ -63,7 +66,9 @@ func (b *Batch) Flush() error {
6366
subSlice := (b.itemsToSave)[0:b.batchPosition]
6467
b.itemsToSave = make([]interface{}, b.batchSize, b.batchSize)
6568
b.batchPosition = 0
66-
return b.flushHandler(subSlice)
69+
err := b.flushHandler(subSlice)
70+
subSlice = nil
71+
return err
6772
}
6873

6974
return nil

worker.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ func (w *Worker) start() {
9090
w.jobErrorFn(job, &w.workerContext, err)
9191
}
9292

93+
// nil out data to clue GC
94+
w.workerContext.Data = nil
95+
9396
_, _ = w.logFn("worker%d: completed %s!\n", w.id, job.Name)
9497
case <-w.quitChan:
9598
_, _ = w.logFn("worker%d stopping\n", w.id)

0 commit comments

Comments
 (0)