fastjson icon indicating copy to clipboard operation
fastjson copied to clipboard

Shouldn't ArenaPool call arena.Reset() on Put or on Get?

Open KromDaniel opened this issue 4 years ago • 2 comments

Hey, Not sure this is a bug or by design, I didn't find anything on the docs mention that and I think it made my app OOM

This is the implementation of arena pool:

// Get returns an Arena from ap.
//
// The Arena must be Put to ap after use.
func (ap *ArenaPool) Get() *Arena {
	v := ap.pool.Get()
	if v == nil {
		return &Arena{}
	}
	return v.(*Arena)
}

// Put returns a to ap.
//
// a and objects created by a cannot be used after a is put into ap.
func (ap *ArenaPool) Put(a *Arena) {
	ap.pool.Put(a)
}

However (AFAIK), pools usually should call reset on returned object so shouldn't Put implementation should be:

a.Reset()
ap.pool.Put(a)

I can call .Reset myself but since the pool is not doing that, I'm afraid that I might be missing something?

Would really appreciate if you have time to look, Thanks!

KromDaniel avatar Feb 08 '21 14:02 KromDaniel

Same question.

develar avatar Aug 17 '21 13:08 develar

Same here... I see that the 'b' field is keep growing if I'm not using Reset()

saartamir avatar Jan 09 '22 16:01 saartamir