Skip to content

Memory Leak When Passing Context #238

@ZirgVoice

Description

@ZirgVoice

Describe the issue

I’ve discovered a memory leak when using Vapor with Leaf templates. The leak only occurs when a context is passed to the renderer, regardless of whether the context is actually used in the .leaf file or not. The template can even be completely empty — the leak still happens. If no context is passed at all, there is no memory leak.

Vapor version

4.114.1

Operating system and version

macOS 15.5

Swift version

Swift Package Manager - Swift 6.1.0

Steps to reproduce

  1. Define a route that renders a Leaf template and passes any context.
  2. Use an .leaf template file.
  3. Send repeated requests to this route using a loop (e.g. curl loop with 100 iterations) to make the leak more visible.
  4. Observe memory usage — it keeps increasing steadily.

Note: The loop is used to accelerate the leak for demonstration purposes. Sending requests manually makes the leak harder to observe.

When changing req.view.render("some.leaf", context) to req.view.render("some.leaf") (i.e. no context), memory usage stays stable.

Outcome

No response

Additional notes

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions