SoFunction
Updated on 2025-04-12

Summary of memory leak issues in electron-vue development environment


 "dependencies": {
  "vue": "^2.5.16"
 },
 "devDependencies": {
  "ajv": "^6.5.0",
  "babel-core": "^6.26.3",
  "babel-loader": "^7.1.4",
  "babel-plugin-transform-runtime": "^6.23.0",
  "babel-preset-env": "^1.7.0",
  "babel-preset-stage-0": "^6.24.1",
  "babel-register": "^6.26.0",
  "babili-webpack-plugin": "^0.1.2",
  "cfonts": "^2.1.2",
  "chalk": "^2.4.1",
  "copy-webpack-plugin": "^4.5.1",
  "cross-env": "^5.1.6",
  "css-loader": "^0.28.11",
  "del": "^3.0.0",
  "devtron": "^1.4.0",
  "electron": "3.0.0",
  "electron-builder": "^20.19.2",
  "electron-debug": "^1.5.0",
  "electron-devtools-installer": "^2.2.4",
  "file-loader": "^1.1.11",
  "html-webpack-plugin": "^3.2.0",
  "mini-css-extract-plugin": "0.4.0",
  "multispinner": "^0.2.1",
  "node-loader": "^0.6.0",
  "style-loader": "^0.21.0",
  "url-loader": "^1.0.1",
  "vue-html-loader": "^1.2.4",
  "vue-loader": "^15.2.4",
  "vue-style-loader": "^4.1.0",
  "vue-template-compiler": "^2.5.16",
  "webpack": "^4.15.1",
  "webpack-cli": "^3.0.8",
  "webpack-dev-server": "^3.1.4",
  "webpack-hot-middleware": "^2.22.2",
  "webpack-merge": "^4.1.3"
 }

electron test version 3.0.0, 4.0.0, 4.2.6

Problem description

In the development environment, after modifying the main process to save, one or two more electron processes will appear each time. According to group members' feedback 2.0.8, this problem also exists, but the frequency of occurrence is low.

Troubleshooting process and solution ideas

1. First, I looked at it first, but I didn’t find anything unusual. I only started one application and used () to force it out before each exit. However, there was no improvement. So I created a new project to test it.
2. After the creation is completed (electron v4.0.0), it is found that not a new process will appear every time you save it. After multiple tests, it is found that the problem is that after the saving is completed, the main process has not been generated successfully, and then saved again. So the process was created many times, but only the initial process was killed, causing memory leaks.
3. I found a method about killing the process

   if (electronProcess && ) {
    manualRestart = true
    ()
    electronProcess = null
    startElectron()

    setTimeout(() => {
     manualRestart = false
    }, 5000)
   }

4. Well, he killed the process directly through the call, and then caused this problem, so he modified it. After the modification, the code is as follows. Pay attention to introducing exec and then delete the delay. It feels that the entire program runs much faster, hahaha

   if (electronProcess && ) {
    manualRestart = true
    const pid = 
    exec(`TASKKILL /F /IM `, function (err, data) {
     if (err) (err)
     else ('kill pid: ' + pid + ' success!')
     electronProcess = null
     startElectron()
     manualRestart = false
    })
   }

Summarize

After solving the problem, I looked at the version update record. In the 2.0.8-3.0.0 version update record, I did not find that update record would cause this problem. The time was limited, and I did not see which version caused this problem. I was poor in the skill and never found the reason for it.

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.