totaljs / framework

Node.js framework
http://www.totaljs.com
Other
4.36k stars 450 forks source link

Kind off memory leak on global variables. #743

Closed elomraydino closed 4 years ago

elomraydino commented 4 years ago

I observe a sort off memory leak using GLOBAL to store app settings that i don't want to load from db at each request. I first put them directly in GLOBAL then in MAIN but still have the same behavior. After some hours and sometime some days those settings are not accessible any more. Bellow the way I load an use them. The app is currently running on node 10.18.0 but I plan to move to node 12 suspecting a nodejs memory leak bug.

//Loading at app start
F.on('load', function () {
    //Load settings from db.
    var Setting = MODEL('setting').model; //Mongoose model
    Setting.find({
        alive: true,
    }).then((settings) => {
        settings.forEach(setting => {
            MAIN[setting.ref] = setting.value; // value is Object
        });
        console.log('Settings loaded');
    }).catch((err) => {
        console.log('Error loading settings -->> ', err.message);
    });
});
<!-- usage in view -|- address, phone, email don't show anymore on the page after the app run for some days-->
<div class="tab-pane fade show active" id="nav-home" role="tabpanel" aria-labelledby="nav-home-tab">
    <h5>@(Adresse)</h5>
    <p>@{MAIN.identity.address}</p>
    <h5>@(Contact)</h5>
    <p><i class="fa fa-phone fa-fw"></i> @{MAIN.identity.phone}</p>
    <p><i class="fa fa-envelope fa-fw"></i> @{MAIN.identity.email}</p>
</div>
petersirka commented 4 years ago

I can't help you, this is very small amout of information. We provide more than 100 apps and without any problem. Memory leak can be caused with storing a lot of information in objects.

Is the problem in view only or the problem is in entire app?

elomraydino commented 4 years ago

The objects are js objects containing simple information (string, int, boolean) like user info, report schedule time and api ids... the problem is in in the entire app. Thanks for the advises; I will try them! I will close the issue for now. But in case you find something about this, please share.

petersirka commented 4 years ago

OK, just let me know.