From ac4d8fe4788e24ef27429276bde6dadfbf2a5c5d Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sat, 27 Jun 2015 20:42:49 -0700 Subject: [PATCH] Add free() method for proxyReader to aggressively de-allocate Read data, to handle certain out of memory conditions There are still some more out there --- pkg/storage/drivers/donut/donut.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/storage/drivers/donut/donut.go b/pkg/storage/drivers/donut/donut.go index 986a62ee5..442d3a54e 100644 --- a/pkg/storage/drivers/donut/donut.go +++ b/pkg/storage/drivers/donut/donut.go @@ -505,7 +505,12 @@ type proxyReader struct { object string } +func (r *proxyReader) free(p []byte) { + p = nil + go debug.FreeOSMemory() +} func (r *proxyReader) Read(p []byte) (n int, err error) { + defer r.free(p) n, err = r.reader.Read(p) if err == io.EOF || err == io.ErrUnexpectedEOF { ok := r.driver.objects.Append(r.object, p[0:n]) @@ -582,9 +587,6 @@ func (d donutDriver) CreateObject(bucketName, objectName, contentType, expectedM } return "", iodine.New(err, errParams) } - // free up - go debug.FreeOSMemory() - objectMetadata, err := d.donut.GetObjectMetadata(bucketName, objectName) if err != nil { return "", iodine.New(err, nil)