Single page application show image use too much ram


#1

Hi, I am building a application to Windows platform. My app show about 20 image in time and change another image by remove div have old image and use innerHTML to write new div have url new image. I aware that when I change image, electron increase about 5MB. After use 30 mins electron used 500MB and no decrease. If I minimize app, it decrease to 150MB. How can I decrease ram used without minimize app? :disappointed:


Electron not letting go of memory
#2

This is just a guess. JavaScript is a garbage-collected language. If the memory isn’t reducing over time, then it means you’re holding on to references to things … so something still holds a reference to the images you’ve already loaded?


#3

I don’t think it because Javascript. When I check process.memoryUsage() and use --js-flags="–expose-gc" to force garbage collection, I see heapUsed reduce but rss memory still increase :weary: I think it because chromium cache my image and doesn’t free until reload BrowserWindow :weary:
My code HTML like this and I’m sure no references to it

'<div class="col-sm-3 col-lg-3 col-md-3">\
            <div class="thumbnail">\
                <div class="picCard">\
                    <a href="#"><img src="demo/default-app.png" style="background :url(\'' + _icon + '\') no-repeat center; background-size:contain;"></img></a>\
                </div>\
                <div class="caption">\
                    <h5 class="titleCard"><a href="#">' + _title + '</a>\
                    </h5>\
                    <p class="subCard"><a href="#">' + _sub + '.</a></p>\
                    <p class="btnCard">\
                        <a class="btn btn-default" name="' + _appID + '">' + _action + '</a>\
                    </p>\
                </div>\
            </div>\
        </div>'

#4

Here is graph when I use without force gc. I think it auto gc still ok


#5

Update: New function clearCache in new version is what I want :smiley:
Github


Electron not letting go of memory