|
|
@@ -139,18 +139,18 @@ const (
|
|
|
// so structFieldInfo fits into 8 bytes
|
|
|
maxLevelsEmbedding = 14
|
|
|
|
|
|
- // finalizers are used? to Close Encoder/Decoder when they are GC'ed
|
|
|
- // so that their pooled resources are returned.
|
|
|
+ // useFinalizers=true configures finalizers to release pool'ed resources
|
|
|
+ // acquired by Encoder/Decoder during their GC.
|
|
|
//
|
|
|
// Note that calling SetFinalizer is always expensive,
|
|
|
// as code must be run on the systemstack even for SetFinalizer(t, nil).
|
|
|
//
|
|
|
- // We document that folks SHOULD call Close() when done, or they can
|
|
|
+ // We document that folks SHOULD call Release() when done, or they can
|
|
|
// explicitly call SetFinalizer themselves e.g.
|
|
|
- // runtime.SetFinalizer(e, (*Encoder).Close)
|
|
|
- // runtime.SetFinalizer(d, (*Decoder).Close)
|
|
|
- useFinalizers = false
|
|
|
- removeFinalizerOnClose = false
|
|
|
+ // runtime.SetFinalizer(e, (*Encoder).Release)
|
|
|
+ // runtime.SetFinalizer(d, (*Decoder).Release)
|
|
|
+ useFinalizers = false
|
|
|
+ removeFinalizerOnRelease = false
|
|
|
)
|
|
|
|
|
|
var oneByteArr [1]byte
|
|
|
@@ -542,22 +542,23 @@ type BasicHandle struct {
|
|
|
// (for Cbor and Msgpack), where time.Time was not a builtin supported type.
|
|
|
TimeNotBuiltin bool
|
|
|
|
|
|
- // DoNotClose configures whether Close() is implicitly called after an encode or
|
|
|
+ // ExplicitRelease configures whether Release() is implicitly called after an encode or
|
|
|
// decode call.
|
|
|
//
|
|
|
// If you will hold onto an Encoder or Decoder for re-use, by calling Reset(...)
|
|
|
- // on it, then you do not want it to be implicitly closed after each Encode/Decode call.
|
|
|
+ // on it or calling (Must)Encode repeatedly into a given []byte or io.Writer,
|
|
|
+ // then you do not want it to be implicitly closed after each Encode/Decode call.
|
|
|
// Doing so will unnecessarily return resources to the shared pool, only for you to
|
|
|
// grab them right after again to do another Encode/Decode call.
|
|
|
//
|
|
|
- // Instead, you configure DoNotClose=true, and you explicitly call Close() when
|
|
|
+ // Instead, you configure ExplicitRelease=true, and you explicitly call Release() when
|
|
|
// you are truly done.
|
|
|
//
|
|
|
// As an alternative, you can explicitly set a finalizer - so its resources
|
|
|
// are returned to the shared pool before it is garbage-collected. Do it as below:
|
|
|
- // runtime.SetFinalizer(e, (*Encoder).Close)
|
|
|
- // runtime.SetFinalizer(d, (*Decoder).Close)
|
|
|
- DoNotClose bool
|
|
|
+ // runtime.SetFinalizer(e, (*Encoder).Release)
|
|
|
+ // runtime.SetFinalizer(d, (*Decoder).Release)
|
|
|
+ ExplicitRelease bool
|
|
|
|
|
|
be bool // is handle a binary encoding?
|
|
|
js bool // is handle javascript handler?
|