question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proxies permanently leak memory

See original GitHub issue

Edit: see comments below for real issue (memory leak)

Objects returned by Comlink calls can’t be used for further calls. Example:

<!-- index.html -->
<!doctype html>
<script src="comlink.js"></script>
<script>
"use strict";
{
	const worker = new Worker("worker.js");
	const api = Comlink.proxy(worker);

	async function start()
	{
		const app = await new api.App();
		const ret = await app.getObject();
		await ret.log();		// error
	}
	
	start();
}
</script>
// worker.js
"use strict";

importScripts("comlink.js");

class ReturnedObject {
	log()
	{
		console.log("ReturnedObject log() method");
	}
}

class App {
	getObject()
	{
		return new ReturnedObject();
	}
}

Comlink.expose({App, ReturnedObject}, self);

In index.html, the call to await ret.log() throws TypeError: ret.log is not a function. ret has become an empty object (i.e. {}) which seems to be because it got posted raw. This appears to prevent using comlink with APIs that return other objects, which is quite a severe limit on the complexity of APIs that can be used.

I would be super interested if you figure out a way to fix this without leaking memory, since it’s the same problem that is blocking via.js being usable in production.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:12

github_iconTop GitHub Comments

4reactions
surmacommented, Jan 3, 2018

Thanks for the amazing work, @AshleyScirra. I am talking to Chromies as well, so let’s all continue in the bug you opened.

Leaving this issue open until we have come to a conclusion/fix.

3reactions
surmacommented, May 28, 2020

I implemented usage of the WeakRef proposal on a branch that takes care of propagating GC’ing of proxies to the worker. If you fancy, take a look: #469

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuring the memory leak policy - IBM
When a classloader memory leak is detected, WebSphere® Application Server notifies you with informational messages in the log and by taking ...
Read more >
Memory leak inside Castle - Google Groups
When "container.Kernel.ReleaseComponent(controller)" is called, this controller is not disposed and remains in memory forever - it introduce memory leak. The ...
Read more >
Weakmap memory leak - javascript - Stack Overflow
I'm setting as Weakmap keys ES6 Proxies, all with the same handlers. I've created a wrapper class that, in its constructor iterates the...
Read more >
OEM Module Causing Memory Leak On+ APX (ASM Proxy ...
Resident memory of +APX process seems to be leaking; it is increasing slowly but steadily and is now over 1.1 GB. RSS_MEM_usage by...
Read more >
Memory management - JavaScript - MDN Web Docs
In contrast, JavaScript automatically allocates memory when objects are created ... Circular references are a common cause of memory leaks.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found