gaearon / react-hot-loader

Tweak React components in real time. (Deprecated: use Fast Refresh instead.)
http://gaearon.github.io/react-hot-loader/
MIT License
12.26k stars 801 forks source link

React hot loader leaking? #1180

Open trusktr opened 5 years ago

trusktr commented 5 years ago

If you are reporting a bug or having an issue setting up React Hot Loader, please fill in below. For feature requests, feel free to remove this template entirely.

Description

What you are reporting:

Seems like there's a leak in the hot loader? For each instance of my Annotator component, I see a retainer hierarchy like the following in the Heap snapshot I took in the Memory tab:

screen shot 2019-02-13 at 7 35 17 pm

Expected behavior

What you think should happen:

I think that the gui you see at the top of the retainer hierarchy should be garbage collected, and my component is done with it, but it is leaking. I see lots of React stuff in the retainer stack.

Actual behavior

What actually happens:

The yellow-highlighted objects in the stack are the only things that JS has references to, which looks to be the enter() function, which seems related to React hot loader.

Environment

React Hot Loader version: 4.6.5

Run these commands in the project folder and fill in their results:

  1. node -v: v8.11.3
  2. npm -v: 6.5.0

Then, specify:

  1. Operating system: macOS
  2. Browser and version:
{
    "node":"10.2.0",
    "v8":"6.6.346.32",
    "electron":"3.0.9",
    "chrome":"66.0.3359.181"
}

Reproducible Demo

No simple reproduction yet.

trusktr commented 5 years ago

Hmmm, I ran delete window.reactHotLoaderGlobal, and then the retainer stack changed to the following (notice the yellow highlights):

screen shot 2019-02-13 at 7 52 05 pm

Maybe this is not related to react hot loader then.

theKashey commented 5 years ago

reactHotLoaderGlobal is basically React-Hot-Loader as a whole module. Including maps(knownClassComponents), holding every component you have, including proxy weak maps, and some other stuff.

And you are right - there is no delete operation defined. PS: And you can't "delete" RHL as a variable. You are deleting no more than just copy.

trusktr commented 5 years ago

How can I ensure that in production there's no react-hot-loader stuff imported at all?

theKashey commented 5 years ago

ReactHotLoader global variable should not exists. It would not if NODE_ENV is set to production.

trusktr commented 5 years ago

ReactHotLoader global variable should not exists.

Did you mean the reactHotLoaderGlobal variable?

theKashey commented 5 years ago

yep. If it does not exist - ReactHotLoader does not exists.