-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 3.6, 3.6.1
-
Component/s: BSON, Performance, Query Operations
-
Environment:Windows, Mongo v3.4.5, PyMongo v3.6, v3.6.1
A memory leak occurs when querying from a collection that has CodecOptions: tz_aware=True and tz_info=utc.
Basic code that exhibits this issue looks like this:
from datetime import timezone
from pymongo import MongoClient
from bson.codec_options import CodecOptions
codec_options = CodecOptions(tz_aware=True, tzinfo=timezone.utc)
client = MongoClient('localhost:27017')
database = client['my_database']
collection = database['my_collection'].with_options(codec_options)
cursor = collection.find({})
for data in cursor:
pass
cursor.close()
del cursor
del data
When this code is run repeatedly with memory profiling, the cursor iteration uses 10MB of memory each time and never releases the memory. (the collection is about 10MB, each object has several datetimes).
Using gc.collect() does not help.
The memory leak goes away if tzinfo is not set:
codec_options = CodecOptions(tz_aware=True)
The default is UTC anyway, so that works as a temporary solution. If tz_info is set to bson.tz_util.utc the memory leak still happens.
- is caused by
-
PYTHON-222 PyMongo timezone transparency enhancement request
- Closed
- is depended on by
-
PYTHON-1557 Release PyMongo 3.7
- Closed