multer icon indicating copy to clipboard operation
multer copied to clipboard

Why does Multer does not release memory?

Open KarimNashaat opened this issue 4 months ago • 1 comments

I am developing node application to upload files, I can see that when multer receives a request with file 200KB for example, it then holds 400KB in the memory and does not release it even after the request finishes until the app receives a new request and do the same with the next request.

`const multer = require("multer"); const storage = multer.memoryStorage(); const upload = multer({ storage: storage });

const app = express(); const port = process.env.PORT || 3002;

app.use(express.json());

app.post("/submitRequest", upload.single("file"), async (req, res) => { return res.send('ok') });

const server = app.listen(port, () => { console.log(Server is running on https://localhost:${port}); });

console.log('Server started at:', new Date().toLocaleString()); Screenshot 2024-02-09 213757 `

KarimNashaat avatar Feb 09 '24 19:02 KarimNashaat

Not sure. My guess is it's loading the data in memory instead of streaming it. version 2.0.0-rc.4 introduces the stream property so user land code can pipe it directly to a write stream for better memory performance.

joeyguerra avatar Apr 01 '24 22:04 joeyguerra