Created
December 30, 2018 11:46
-
-
Save n6g7/4d9d9af8eb5b943b61c89c1c6fa29a3b to your computer and use it in GitHub Desktop.
ReactPDF memory leak reproduction
This file contains 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
const React = require("react") | |
const ReactPDF = require("@react-pdf/renderer").default | |
const { Document, Page, Text } = ReactPDF | |
function Component() { | |
return React.createElement( | |
Document, | |
null, | |
React.createElement( | |
Page, | |
{ size: "A4" }, | |
// keep this line | |
React.createElement(Text, null, "Hello"), | |
), | |
) | |
} | |
async function go(n) { | |
for (let i = 1; i <= n; i++) { | |
// await ReactPDF.renderToStream(React.createElement(Component)) | |
await ReactPDF.render(React.createElement(Component), `out/${i}.pdf`) | |
const memoryUsage = process.memoryUsage().heapUsed / (1 << 20) | |
console.log(JSON.stringify({ i, memoryUsage })) | |
} | |
} | |
go(1000) |
This file contains 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
{ | |
"name": "leak", | |
"version": "1.0.0", | |
"main": "leaktest.js", | |
"license": "MIT", | |
"scripts": { | |
"data": "yarn test | jq -R 'fromjson? | select(type == \"object\").memoryUsage'", | |
"graph": "yarn data | grep '^\\d' | spark", | |
"test": "node leaktest.js" | |
}, | |
"dependencies": { | |
"@react-pdf/renderer": "^1.1.0", | |
"react": "^16.7.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run
yarn test
and seememoryUsage
going up with each render.