diff --git a/array.go b/array.go index ac3e17c8..1a746a53 100644 --- a/array.go +++ b/array.go @@ -623,6 +623,7 @@ func (a *arrayObject) MemUsage(ctx *MemUsageContext) (memUsage uint64, err error if err := ctx.Descend(); err != nil { return memUsage, err } + defer ctx.Ascend() if ctx.ArrayLenExceedsThreshold == nil { return memUsage, errArrayLenExceedsThresholdNil @@ -640,7 +641,6 @@ func (a *arrayObject) MemUsage(ctx *MemUsageContext) (memUsage uint64, err error return memUsage, err } - ctx.Ascend() return memUsage, nil } @@ -661,6 +661,5 @@ func (a *arrayObject) MemUsage(ctx *MemUsageContext) (memUsage uint64, err error } } - ctx.Ascend() return memUsage, nil } diff --git a/array_sparse.go b/array_sparse.go index 89f23285..2e3863a1 100644 --- a/array_sparse.go +++ b/array_sparse.go @@ -535,6 +535,7 @@ func (a *sparseArrayObject) MemUsage(ctx *MemUsageContext) (memUsage uint64, err if err := ctx.Descend(); err != nil { return SizeEmptyStruct, err } + defer ctx.Ascend() // sparseArrayObject overhead memUsage = SizeEmptyStruct @@ -552,7 +553,6 @@ func (a *sparseArrayObject) MemUsage(ctx *MemUsageContext) (memUsage uint64, err return memUsage, err } - ctx.Ascend() return memUsage, nil } @@ -571,7 +571,5 @@ func (a *sparseArrayObject) MemUsage(ctx *MemUsageContext) (memUsage uint64, err } } - ctx.Ascend() - return memUsage, err } diff --git a/builtin_map.go b/builtin_map.go index 6922486d..c0fc5b85 100644 --- a/builtin_map.go +++ b/builtin_map.go @@ -137,6 +137,7 @@ func (mo *mapObject) MemUsage(ctx *MemUsageContext) (memUsage uint64, err error) if err := ctx.Descend(); err != nil { return memUsage, err } + defer ctx.Ascend() memUsage, err = mo.baseObject.MemUsage(ctx) if err != nil { @@ -176,8 +177,6 @@ func (mo *mapObject) MemUsage(ctx *MemUsageContext) (memUsage uint64, err error) } } - ctx.Ascend() - return memUsage, nil } diff --git a/builtin_set.go b/builtin_set.go index c393ae36..026aaa12 100644 --- a/builtin_set.go +++ b/builtin_set.go @@ -393,6 +393,7 @@ func (so *setObject) MemUsage(ctx *MemUsageContext) (memUsage uint64, err error) if err := ctx.Descend(); err != nil { return memUsage, err } + defer ctx.Ascend() memUsage, err = so.baseObject.MemUsage(ctx) if err != nil { @@ -434,7 +435,5 @@ func (so *setObject) MemUsage(ctx *MemUsageContext) (memUsage uint64, err error) } } - ctx.Ascend() - return memUsage, nil } diff --git a/object.go b/object.go index f78102b4..928b8c15 100644 --- a/object.go +++ b/object.go @@ -1946,6 +1946,7 @@ func (o *baseObject) MemUsage(ctx *MemUsageContext) (memUsage uint64, err error) if err := ctx.Descend(); err != nil { return 0, err } + defer ctx.Ascend() memUsage = SizeEmptyStruct if ctx.ObjectPropsLenExceedsThreshold(len(o.propNames)) { @@ -1981,8 +1982,6 @@ func (o *baseObject) MemUsage(ctx *MemUsageContext) (memUsage uint64, err error) } } - ctx.Ascend() - return memUsage, nil } diff --git a/proxy.go b/proxy.go index 395c3b0b..a10ad7b7 100644 --- a/proxy.go +++ b/proxy.go @@ -1063,6 +1063,7 @@ func (p *proxyObject) MemUsage(ctx *MemUsageContext) (memUsage uint64, err error if err := ctx.Descend(); err != nil { return 0, err } + defer ctx.Ascend() memUsage = SizeEmptyStruct inc, err := p.baseObject.MemUsage(ctx) @@ -1087,8 +1088,6 @@ func (p *proxyObject) MemUsage(ctx *MemUsageContext) (memUsage uint64, err error } } - ctx.Ascend() - return memUsage, nil }