Repository: next.js
Issue: Memory issue with API routes and middleware
Labels: create-next-app,bug,Middleware,Pages Router

### Link to the code that reproduces this issue

https://github.com/a-hyssopus/nextjs_memory_issue

### To Reproduce

1. `bun/npm install`
2. `docker build -t memory_repo .`
3. `docker run -p 3000:3000 memory_repo`
4. `docker stats` in a new terminal tab
5. Click the "Send POST request of normal size" button in application. Observe the behaviour of stats in the tab which tracks Docker, and pay attention to the memory consumption.
6. Click "Send POST request of huge size" button, observe skyrocketed memory usage in Docker stats.

### Current vs. Expected behavior

**Actual result**:
Having `middleware.js` (or `.ts`) and reaching out to a BE endpoint through an API route makes memory consumption raise significantly if a huge request (>50 MB) or a sequence of relatively big requests are sent. 
**A very important note**: it only happens when **both** `middleware` and API routes are used. 

All tested scenarios are also listed in README of reproduction repo and have tags assigned (check README):

1. Reproduction created with API route (with `getOnProxyInit`) and `middleware`: hits 940 MB when a 400 MB request is sent, and although error was returned from server, precisely HTTP 413, the memory consumption doesn't decrease at all
2. Removed `getOnProxyInit` from API route: the same situation as above
3. Removed `middleware.js`: memory consumption doesn't raise at all
4. Commented out API route, but restored `middleware.ts`: memory consumption doesn't raise at all
5. Restored API route with `bodyParser: false`: the same as in 1 and 2
6. Completely removed `httpProxyMiddleware`: hit the value >1 GB and never came back to normal values

**The main points here are**:

1. Removal of `middleware.js` but preservation of API route doesn't trigger high memory consumption
2. Removal of API route but preservation of `middleware.js` doesn't trigger high memory consumption

**Expected result**:
I expect no high memory consumption when a network call happens in a project that has both API routes and middleware present in a project, if neither of these read/modify request's body. I also expect `bodyParse: false` to improve the situation. 

### Provide environment information

```bash
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.5.0: Wed May  1 20:12:58 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6000
  Available memory (MB): 32768
  Available CPU cores: 10
Binaries:
  Node: 18.20.0
  npm: 10.5.0
  Yarn: 1.22.22
  pnpm: 9.7.0
Relevant Packages:
  next: 14.2.7 // Latest available version is detected (14.2.7).
  eslint-config-next: 14.2.7
```


### Which area(s) are affected? (Select all that apply)

create-next-app, Middleware, Pages Router, App Router

### Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local), Other (Deployed)

### Additional context

**Edit:** Tested with Next 15.0.3 and App router, the issue persists. Check the branch `app_router` and follow the instructions from above to see the result.

_No response_