Skip to content

Commit

Permalink
Return the memory after scrypt to the OS.
Browse files Browse the repository at this point in the history
Previously a runtime.GC was being invoked which forced it to release the
memory as far as the garbage collector is concerned, but the memory was
not released back to the OS immediatley.  This modification allows the
memory to be released immedately since it won't be needed again until the
next wallet unlock.
  • Loading branch information
davecgh committed Feb 1, 2015
1 parent a473563 commit 51e3d5f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions snacl/snacl.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"encoding/binary"
"errors"
"io"
"runtime"
"runtime/debug"

"golang.org/x/crypto/nacl/secretbox"
"golang.org/x/crypto/scrypt"
Expand Down Expand Up @@ -129,7 +129,7 @@ func (sk *SecretKey) deriveKey(password *[]byte) error {
// example, if your scrypt parameters are such that you require 1GB and
// you call it twice in a row, without this you end up allocating 2GB
// since the first GB probably hasn't been released yet.
runtime.GC()
debug.FreeOSMemory()

return nil
}
Expand Down

0 comments on commit 51e3d5f

Please sign in to comment.