Skip to content

Commit

Permalink
fix: never remove ipc callback & mem never be released (#4274)
Browse files Browse the repository at this point in the history
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
  • Loading branch information
f91kdash and lucasfernog committed Jun 5, 2022
1 parent 53ae13d commit f72cace
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changes/fix-memory-leak-command.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri": patch
"api": patch
---

Fixes a memory leak in the command system.
2 changes: 1 addition & 1 deletion core/tauri/scripts/bundle.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions core/tauri/scripts/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@
return new Promise(function (resolve, reject) {
var callback = window.__TAURI__.transformCallback(function (r) {
resolve(r)
delete window[error]
delete window[`_${error}`]
}, true)
var error = window.__TAURI__.transformCallback(function (e) {
reject(e)
delete window[callback]
delete window[`_${callback}`]
}, true)

if (typeof cmd === 'string') {
Expand Down
4 changes: 2 additions & 2 deletions tooling/api/src/tauri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ async function invoke<T>(cmd: string, args: InvokeArgs = {}): Promise<T> {
return new Promise((resolve, reject) => {
const callback = transformCallback((e: T) => {
resolve(e)
Reflect.deleteProperty(window, error)
Reflect.deleteProperty(window, `_${error}`)
}, true)
const error = transformCallback((e) => {
reject(e)
Reflect.deleteProperty(window, callback)
Reflect.deleteProperty(window, `_${callback}`)
}, true)

window.__TAURI_IPC__({
Expand Down

0 comments on commit f72cace

Please sign in to comment.