1

I have an issue with protobuf marshalling consuming a lot of memory. Over the time it looks like a memory leak: process consumes a lot of heap and finally gets killed by OOM. The service is a networking cache for protobuf objects and the vast majority are read-requests.

A brief look into a heap profile points to protobuf marshalling as one of the main contributors.

Can someone explain why this memory is not reclaimed? In my mind, marshaling should not add anything to memory usage since the response buffers are sent. Does protobuf retains memory for future reuse?

Here is the relevant part of go tool pprof -pdf binary heap.txt

Brandon_J
  • 195
  • 3
  • 17
dkrot
  • 11
  • 3
  • 1
    I suspect that the issue is not in the protobuf library code (it's possible, but that code is pretty well tested!). It's more likely that your code is hanging on to the reference `Marshal` returns (possibly due to a Goroutine leak) so the garbage collector cannot release it. Unfortunately without code (ideally a [minimal, reproducible, example](https://stackoverflow.com/help/minimal-reproducible-example)) it's difficult to help. [This question](https://stackoverflow.com/q/19094099/11810946) might be of use. – Brits Sep 11 '22 at 00:35

0 Answers0