Improve attachment memory allocation (#105)
* Improve attachment memory allocation * added explicit garbage collection * redundant GC * added GCs in attachment processor and a FreeOSMemory helper * added changelog * linting * Remove commented call to debug.FreeOSMemory Co-authored-by: marin thiercelin <marin.thiercelin@pm.me> Co-authored-by: marinthiercelin <marin.thiercelin@epfl.ch>
This commit is contained in:
parent
75f27fd1df
commit
6105a3bcc0
3 changed files with 30 additions and 2 deletions
|
|
@ -29,6 +29,9 @@ func (ap *AttachmentProcessor) Process(plainData []byte) {
|
|||
if _, err := (*ap.w).Write(plainData); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if ap.garbageCollector > 0 {
|
||||
defer runtime.GC()
|
||||
}
|
||||
}
|
||||
|
||||
// Finish closes the attachment and returns the encrypted data.
|
||||
|
|
@ -36,19 +39,29 @@ func (ap *AttachmentProcessor) Finish() (*PGPSplitMessage, error) {
|
|||
if ap.err != nil {
|
||||
return nil, ap.err
|
||||
}
|
||||
|
||||
if err := (*ap.w).Close(); err != nil {
|
||||
return nil, errors.Wrap(err, "gopengpp: unable to close writer")
|
||||
}
|
||||
|
||||
if ap.garbageCollector > 0 {
|
||||
ap.w = nil
|
||||
runtime.GC()
|
||||
}
|
||||
|
||||
if err := (*ap.pipe).Close(); err != nil {
|
||||
return nil, errors.Wrap(err, "gopengpp: unable to close pipe")
|
||||
}
|
||||
|
||||
ap.done.Wait()
|
||||
splitMsg := ap.split
|
||||
|
||||
if ap.garbageCollector > 0 {
|
||||
runtime.GC()
|
||||
ap.pipe = nil
|
||||
ap.split = nil
|
||||
defer runtime.GC()
|
||||
}
|
||||
return ap.split, nil
|
||||
return splitMsg, nil
|
||||
}
|
||||
|
||||
// newAttachmentProcessor creates an AttachmentProcessor which can be used to encrypt
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue