0

I have a very simple upload form in an Express app.

The code that receive the form submit is like that:

app.post('/import', function(req, res) {
    res.render('import-complete');
});

When I start the node server I have 60MB of memory used by the node process. After the form is submitted, the file is uploaded (250MB) and the memory usage increases and reach ~300MB. At the end of the upload, the memory usage remains ~300MB without "going down".

So, in the "app.post" there is no code that can cause the memory leak. what's happening?

Angelo Iasevoli
  • 100
  • 1
  • 6

1 Answers1

2

You are probably looking at the allocated virtual memory that your node process receives. Since you load that 250MB file into memory, your node process is allocated 300 MB of memory but the actual usage is much lower afterwards. The memory from that file is garbage collected relatively quickly after the route is handled but your process still has that allocation even if its not using it. You can allocate much more virtual memory than there is actual physical memory. If there was a memory leak, continually hitting that route with more files would increase the virtual memory.

You can check this out for virtual memory reference: What are the differences between virtual memory and physical memory?

Community
  • 1
  • 1
sheldonk
  • 2,604
  • 3
  • 22
  • 32