Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-3603

Memory leak during find operation

    • Type: Icon: Question Question
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None

      Python version: 3.8.10,  3.8.11
      pymongo version: 4.3.3

      Hello!

      Faced a very strange behavior that looks like a memory leak.
      Briefly about the purpose of this operation and my expectations: this [^mongo_leak_test.py] script (a very simplified mechanism for working with documents that I use in my library) has the goal of iterating over thousands of documents from a collection. While using this script, I expect that every time the function is called, after it ends, all the memory that was used will be freed to the initial state.

      At this stage, I see that after each call, the memory is freed, but not completely, each new 1000 documents (which was not previously in the search, as I understand it) pymongo cursor(potentially) takes + 15mb to the initial state.
      This can also be seen on the graph from the memray profiler:

      I'm somewhat unsure of the specific root cause of this problem, so I'm hoping for your help.[^mongo_leak_test.py]

        1. memray_leak_snapshot.png
          memray_leak_snapshot.png
          32 kB
        2. mongo_doc.json
          9 kB
        3. mongo_leak_test-1.py
          0.9 kB

            Assignee:
            steve.silvester@mongodb.com Steve Silvester
            Reporter:
            v_pidkopai-itssv@kw.com Valentyn Pidkopai
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: