MithrilJS / mithril.js

A JavaScript Framework for Building Brilliant Applications
https://mithril.js.org
MIT License
13.99k stars 926 forks source link

Cleaning up the node cache when we pass the forceRecreation as true in m.render #1561

Closed sbvijaykumar closed 7 years ago

sbvijaykumar commented 7 years ago

Description:

We are using mithril as rendering engine. The problem we have is there are few panes which get rendered based on dynamic queries from database. These queries are independent. The queries are triggered based on some user action and the data received completely replaces the previously rendered data. (BTW we are using Mithril inside Electron app).

Note all these "panes" are divs with specific css id inside a large page with hierarchy of blocks (divs).

All these divs are rendered using Mithril. The data in these panes can be totally different from time to time.

We are seeing huge memory bloat over a period of time as Mithril cache is keeping old redundant nodes.

Steps to Reproduce:

To give an example, consider an IRC app with various channels. When I switch channels I have different set of people. Now if I want to address a specific person then I create a popup from the group which is specific to this channel. This is rendered inside a div. See example of div with id people below.

<div id="container_div">
    <div class="messages"> <!-- all IRC messages for the channel room -->
        <div></div>
        <div></div>
        <div></div>
    </div>
    <div id="people"> <!-- Popup having all people part of the specific channel -->
    </div>
</div>

when I switch channels, the group of people also changes obviously and when we want to show the same popup with new set of people the old DOM nodes should be thrown away.

BTW, our app has 1000s of channels.

We just gave an example a single "pane". There are many such in the page.

Expected:

The memory footprint should be constant for these "replaceableable panes."

Actual:

The problem we have is that over a period of time we have dom nodes of discarded/non-active channel's still existing in Mithril cache. Over a period of hour the app memory footprint reaches to very high level i.e. 100s of MBs.

To work around this problem we tried setting forceRecretion to true when using m.render. That did not solve the problem. We referred to the following issue:
https://github.com/lhorie/mithril.js/issues/171

We were asked to open a new issue for the above-mentioned bug.

dead-claudia commented 7 years ago

@sbvijaykumar Could you create a gist/repo that can be used to reproduce the memory leak? Those are horribly difficult to track down, and I'd also like to see if it also can be replicated with 1.x.

dead-claudia commented 7 years ago

Closing - last v0.2 release has been cut.