Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • A ArduinoJson
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 24
    • Issues 24
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Benoît Blanchon
  • ArduinoJson
  • Issues
  • #1877
Closed
Open
Issue created Feb 22, 2023 by Leedan Johnson@LeedanJohnson

Make shrinkToFit() documents more usable.

  1. Using a DynamicJsonDocument , I read in a document that may be very large.
  2. I then call .shrinkToFit() immediately afterward to free up as much heap memory as possible.
  3. After some processing, I try to replace the existing "updatedAt" field on my document with a new string of the same length.
  4. doc.overflowed() now returns true, and serializing the document includes { "updatedAt": null }

Based on the documentation, I think I understand that this is due to the monotonic allocator never reusing memory, and shrinkToFit() releasing all unused memory.

Ideal solution (for my somewhat specific case): Allow replacing a value to reuse the same memory, provided the new value is smaller or equal to the existing value. This would probably be very involved, and may be impossible without unrealistic changes.

(Hopefully) More practical and general alternative: Allow shrinkToFit() to accept a uint argument specifying some amount of unused memory to retain. What if the document can't shrink at all, or can't shrink enough to offer the requested unused memory? I think it's reasonable that the retained memory be best-effort only.

Assignee
Assign to
Time tracking