Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚡ set raw to nil in JSON to avoid memory leak #2479

Closed
wants to merge 2 commits into from

Conversation

damianham
Copy link

@damianham damianham commented May 26, 2023

Description

1 line change to set raw to nil in c.JSON() to avoid memory leak

Fixes #2470

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • New and existing unit tests pass locally with my changes

@welcome
Copy link

welcome bot commented May 26, 2023

Thanks for opening this pull request! 🎉 Please check out our contributing guidelines. If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

@damianham damianham changed the title Update ctx.go set raw to nil in JSON to avoid memory leak :zap set raw to nil in JSON to avoid memory leak May 26, 2023
@gaby gaby changed the title :zap set raw to nil in JSON to avoid memory leak ⚡ set raw to nil in JSON to avoid memory leak May 28, 2023
@gaby
Copy link
Member

gaby commented May 28, 2023

@damianham Can you take a look at the lint error

@ReneWerner87
Copy link
Member

are you sure this solves the memory problem?
have you already tested this in use?

@damianham damianham closed this May 30, 2023
@damianham
Copy link
Author

No it doesn't

@shohamroditimemphis
Copy link

shohamroditimemphis commented Jul 30, 2023

Hi,
I am experiencing memory leak when I am using with c.Params().
This issue with memory leak was solved in the latest version?

Thanks

@ReneWerner87
Copy link
Member

Hi,
I am experiencing memory leak when I am using with c.Params().
This issue with memory leak was solved in the latest version?

Thanks

There was no memory leak

Pls read the hint box
https://docs.gofiber.io/next/api/ctx#params

@damianham damianham deleted the damianham-patch-1 branch July 31, 2023 20:28
@damianham
Copy link
Author

Hi, I am experiencing memory leak when I am using with c.Params(). This issue with memory leak was solved in the latest version?

Thanks

The memory leak I was experiencing was in in the JSON encoder. I solved it by changing all instances of
return c.JSON(fiber.Map{"result": business})
to
`
res := fiber.Map{"result": business}

outp, _ := json.Marshal(res)

c.Response().Header.SetContentType("application/json")

c.SendString(string(outp))

return nil

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🤗 [Question]: Potential memory leak?
4 participants