Skip to content
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

Why does Multer does not release memory? #1242

Open
KarimNashaat opened this issue Feb 9, 2024 · 2 comments
Open

Why does Multer does not release memory? #1242

KarimNashaat opened this issue Feb 9, 2024 · 2 comments

Comments

@KarimNashaat
Copy link

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
`

@joeyguerra
Copy link

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.

@xiaobaidadada
Copy link

Based on my attempts, I found that the reason might be that the V8 engine does not promptly clean up the buffer variable. Buffers are not managed by V8, but the memory will not be released until the JavaScript variable that references the buffer is cleared. Since the buffer is not very large, V8 does not immediately clear it. Therefore, using the diskStorage method is more memory-efficient as it saves memory better.

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

No branches or pull requests

3 participants