Skip to content

.Net: Bug: Memory leak when sending a byte array in a chat completion #12550

Open
@joe-sch-next

Description

@joe-sch-next

Describe the bug
When sending a byte array to 'GetChatMessageContentsAsync' specifically targeting OpenAi Gpt 4.1. I can see the memory usage spike by 80x the original byte arrays size.

To Reproduce
Steps to reproduce the behavior:

  1. Send a byte array chat completion to GPT 4.1
  2. Monitor memory usage
  3. See it spike by 80x the byte array size.

Expected behavior
I would expect some memory usage to increase, however I do not expect a 80x increase, that seems a bit much?

Screenshots

Image

Image
Here is me passing an image that is around 5MB, prior to uploading (right up to the semantic kernel line) memory usage was around 35MB. After calling the semantic kernel code, memory shoots up to 385MB.

Image
My code... I run my calls in parallel, with there being 2 parallel calls executing at the moment. I have also tried to make them sequential with the same result

Platform

  • Language: C#
  • Source: Microsoft.SemanticKernel 1.49.0 - OpenAI 2.2.0-beta.4
  • AI model: gpt-4.1 (version:2025-04-14)
  • IDE: Rider
  • OS: Windows/Linux

Metadata

Metadata

Assignees

Labels

.NETIssue or Pull requests regarding .NET codebugSomething isn't workingneeds more infoAny issue that is requires more information from contributors

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions