🧵 Memory Leak Report: .stream() and .invoke() Both Cause Memory Growth When Input Is Empty #5685
Unanswered
Venkatesh-Zebra
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
✅ Context
We observe memory growth when using both
.stream()
and.invoke()
with aRunnable
composed of aPromptTemplate
and an LLM (e.g., OpenAI) — only when theconversation_history
input is empty (""
) orNone
.🔍 Reproduction Snippet
Similarly, with
.invoke()
:We see a smaller but still noticeable memory increase.
📌 Observations
Memory leak triggers right at the point
.stream()
is called — even before iteration starts.Leak happens only when
conversation_history
is empty orNone
.Leak occurs with both
.stream()
and.invoke()
Memory growth accumulates with repeated calls, requiring process restart.
❓ Questions for LangChain / LangGraph Team
Why does calling
.stream()
with an empty input cause immediate memory growth even before iteration?Is this a known issue related to input processing, caching, or internal buffers?
Could there be internal objects or retry logic that are not cleaned up properly for empty inputs?
What workarounds or fixes do you recommend to avoid this leak?
Looking forward to your insights!
Description
Using LangChain’s
ChatVertexAI
with theinvoke()
andstream()
methods causes memory growth on each call. The leak happens even after deleting the response and forcing garbage collection. This occurs when the input dictionary is empty ({}
), particularly when theconversation_history
parameter is empty or omitted.Minimal Reproducible Example
To reproduce the issue, install the following packages:
Observed Output from
memory_profiler
Notes
invoke()
call and does not drop.stream()
method shows a smaller but persistent memory increase.(Note: if we run stream method first then it is taking up ~9 MiB)gc.collect()
) does not reclaim memory.conversation_history
.Environment
Operating System:
Linux (Ubuntu 22.04 LTS or equivalent)
Request
Could you please investigate this potential memory leak in
ChatVertexAI
’sinvoke()
andstream()
? It’s blocking usage in long-running applications due to gradual memory bloat.Thank you!
Beta Was this translation helpful? Give feedback.
All reactions