Skip to content

Fix memory leak by caching UI fonts instead of allocating per frame#1

Merged
virtualarchitectures merged 1 commit into
mainfrom
fix/cache-ui-fonts
Apr 30, 2026
Merged

Fix memory leak by caching UI fonts instead of allocating per frame#1
virtualarchitectures merged 1 commit into
mainfrom
fix/cache-ui-fonts

Conversation

@virtualarchitectures
Copy link
Copy Markdown
Owner

Fix memory leak: cache UI fonts instead of allocating per frame

Project.drawUI() was calling mainApplet.createFont() on every frame. At 60 fps this creates over 3,600 font objects per minute which was holding resources that the garbage collector couldn't efficiently reclaim. This was causing memory to climb continuously until the system ran out, even in the empty example project.

The same pattern appeared in seven other methods (createSceneButtons, createScreenButtons, addSelectSceneButton, addSelectScreenButton, createAssignDisplayButtons, createMediaButtons, createGeneratorButtons), which each allocated a fresh font object on every call.

Changes:

  • Added three PFont fields (uiFont14, uiFont16, uiFont20) to Project
  • Initialized all three once in the constructor
  • Replaced all eight createFont() call sites with references to the cached fields

NOTE: This pull request is built on top of and includes the UI updates in my previous pull request. Apologies for not spotting this issue first.

@virtualarchitectures virtualarchitectures merged commit 82e2bfc into main Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant