-
Notifications
You must be signed in to change notification settings - Fork 15.9k
Closed
Labels
Description
What version of protobuf and what language are you using?
Version: v3.5.1
Language: Python
What operating system (Linux, Windows, ...) and version?
System: Linux / Mac
What runtime / compiler are you using (e.g., python version or gcc version)
PythonVersion: 3.7.4
ProtobufPackageVersion: 3.11.3
What did you do?
syntax = "proto3";
message Msg
{
uint32 u32_id = 1;
}
import os, psutil, gc
import tracemalloc
from a_pb2 import Msg
def get_mem():
rss = psutil.Process(os.getpid()).memory_info().rss
print(rss / 1024 / 1024)
def get_unknown_field():
msg = Msg()
unknown_fields = msg.UnknownFields() # it raise memory leak
# print(unknown_fields)
tracemalloc.start()
get_mem()
for i in range(10000000):
get_unknown_field()
gc.collect()
get_mem()
snapshot = tracemalloc.take_snapshot()
top_stats = snapshot.statistics('lineno')
for stat in top_stats:
print(stat)
What did you expect to see
Process's memory will be freed.
What did you see instead?
Python Output:
It looks like the memory has not been freed. May be it's a bug?