-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
fix: fix multiple memory leaks in Text #11619
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contributor
Author
|
Test code (async () => {
// Create a new application
const app = new Application();
// Initialize the application
await app.init({ background: '#1099bb', width: 800, height: 600 });
// Append the application canvas to the document body
function drawGraphicsAndText() {
const removed = app.stage.removeChildren();
removed.forEach(child => {
child.destroy(true)
})
const words = ['Hello', 'World', 'PIXI', 'Graphics', 'Text', 'Random', 'Vue', 'TypeScript', 'Canvas', 'Animation'];
for (let i = 0; i < 500; i++) {
const randomWord = words[Math.floor(Math.random() * words.length)];
const color = Math.random() * 0xFFFFFF;
const fontSize = 12 + Math.random() * 24;
const style = new TextStyle({
fontFamily: 'Arial',
fontSize: fontSize,
fill: color,
fontWeight: 'bold'
});
const text = new Text({
text: randomWord,
style
});
text.x = Math.random() * (app.screen.width - text.width);
text.y = Math.random() * (app.screen.height - text.height);
text.rotation = Math.random() * Math.PI * 2;
app.stage.addChild(text);
}
}
const btn = document.createElement('button')
btn.innerHTML = 'draw'
btn.addEventListener('click', async () => {
for (let i = 0; i < 100; i++) {
drawGraphicsAndText()
await new Promise(rsolve => setTimeout(rsolve, 20))
}
})
document.body.appendChild(btn)
document.body.appendChild(app.canvas);
})(); |
|
pixi.js-base • pixi.js-bunny-mark commit: |
Contributor
Author
mayakwd
reviewed
Aug 18, 2025
Collaborator
|
Other than that, I'd like to admit - numbers are impressive! |
mayakwd
approved these changes
Aug 25, 2025
Collaborator
|
Well done! I appreciate your patience! |
bigtimebuddy
approved these changes
Aug 25, 2025
Contributor
Author
|
Thanks for your guidance 🎉 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
✅ Ready To Merge
Helpful when issues are in the queue waiting to get merged. This means the PR is completed and has t
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.


Description of change
This PR fixes multiple memory leaks in the
Textobject by ensuring that all internal event listeners and caches are properly cleared upon destruction.Specifically, it addresses two main issues:
Textobject's event listener forrenderer.runners.resolutionChangewas not being removed in thedestroy()method.CanvasTextMetricscache was not being cleared, causing cached font style strings to remain in memory.Process of Discovery and Test Results
I discovered these issues while working on an application that frequently creates and destroys a large number of
Textobjects. My initial observation was that memory usage continued to climb even after correctly callingdestroy()on all objects.Using DevTools Performance Monitor and Heap Snapshots, I was able to identify
Textobjects that were not being garbage collected. By analyzing their object retainers, I traced the root cause to two primary culprits: the un-removedresolutionChangelistener and the persistentCanvasTextMetricscache entries.To verify the fix, I created a test case that rapidly creates and destroys
Textobjects. The results are clear:Pre-Merge Checklist
npm run lint)npm run test)