mem0
mem0 copied to clipboard
Bug: Memory leak and thread leak issues in mem0 library
🐛 Describe the bug
Environment
- Python 3.10
- mem0ai==0.1.115
- pymilvus==2.3.2
- Using Milvus as vector store with Azure OpenAI as LLM
Problem
- Memory Leak: Each time Memory.from_config() is called, memory usage increases and never gets released.
- Thread Leak: New threads are created and never terminated,I found the cause is about PostHog module.
- Resource Leak: MilvusClient connections and other resources are not properly cleaned up.
Code
@memory_router.get(path="/test/", summary="Api test", response_model=MemoryResponse)
def test_api():
import psutil
mm = Memory.from_config(DEFAULT_MEM0RY_CONFIG)
result = mm.add(messages=[{"role": "user", "content": "test"}],agent_id="test")
print(f"Memory usage after: {psutil.Process().memory_info().rss/1024/1024}MB")
return MemoryResponse(message="Api test", code=0, success=True, result=[], token_usage={})
Any solution for this, is there a clean method to clean the VectorDB connections and LLM client?
Has v0.1.117 fixed this issue?
We are running v0.1.118 and see a huge amount of threads from posthog on an app that has very low to no traffic. It regularly kills our containers and forces a restart. We are not directly using posthog. It's only required by mem0.