Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about behavior of ReturnToVTPool() and Reset() #64

Open
joe-elliott opened this issue Oct 7, 2022 · 2 comments
Open

Question about behavior of ReturnToVTPool() and Reset() #64

joe-elliott opened this issue Oct 7, 2022 · 2 comments

Comments

@joe-elliott
Copy link

joe-elliott commented Oct 7, 2022

Using this proto:

message Parent {
  option (vtproto.mempool) = true;
  repeated Child children = 1;
  Child one = 2;
}

message Child {
  option (vtproto.mempool) = true;
  uint32 field = 1;
}

When calling ReturnToVTPool() on Parent it calls ResetVT on all children and then calls m.Reset()

func (m *Parent) ResetVT() {
	for _, mm := range m.Children {
		mm.ResetVT()
	}
	m.One.ReturnToVTPool()
	m.Reset()
}

However m.Reset() allocates a new object and overwrites the existing object entirely:

func (x *Parent) Reset() {
	*x = Parent{}

This nils out all fields on the parent throwing away the slice for the GC to handle. Am I missing something? Is there some way to put back into the pool, call ResetVT() but not call Reset()?

@npordash
Copy link

npordash commented Oct 7, 2022

I'm fairly certain it is a bug. I commented about this in #35 (comment) since I saw this behavior when trying to compile using the v0.3.0 tag. I'm still using v0.2.0 right now because of it.

@cyriltovena
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants