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.

Memory Leak in Object.js Editor

See original GitHub issue

General information

Believe I’ve identified the source of memory leak.

We noticed that after visiting a page in our angular app with a json-editor (and a VERY large schema), and then leaving, the app felt sluggish. Digging around in Chrome dev tools confirmed that memory usage climbs significantly after visiting the page and never drops back down.

I’m no expert in memory leaks, but some further digging led me to line 647 in objects.js, where there’s an event listener added directly to the document. I tweaked that code to attach a named function instead of an anonymous function, and then detached the listener in destroy(), and that seemed to prevent the leak.

json-editor version

1.4.0-beta.0

Expected behavior

Memory usage return to previous level after destroying the editor.

Actual behavior

Memory stays bloated. memoryLeakHeapSnapshot

Steps to reproduce the behavior

  1. Go to the Interactive playground
  2. Upload the json setup from below. You’ll notice in the Javascript section I added a couple buttons to destroy and rebuild the editor.
  3. Force garbage collection (in chrome dev tools memory tab) and then take a heap snapshot.
  4. Load in the sample JSON (also below).
  5. Click the “Destroy Form” button
  6. Force GC and take another heap snapshot. You’ll see that memory is still much higher than before. There are a bunch of leftover objects, arrays, detached DOM nodes, etc.

PS. I’m working on the same application as the submitter of #252, @j2jensen.

For now we’ll likely fork and implement the fix in our own application, but would love to submit a PR if the maintainers are supportive.

Has the setup for the interactive demo & json data: memoryLeak.zip

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
corykoncommented, Aug 14, 2019

Memory leak causing us problems was still there in the 2.x branch. Submitted a small PR to fix. #469

0reactions
istvan-aranycommented, Sep 2, 2019

Yea 😃 I solved it in a different way since then though 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Eradicating Memory Leaks In Javascript - LambdaTest
A Memory leak can be defined as a piece of memory that is no longer being used or required by an application but...
Read more >
The Secrets of Memory Leaks in JavaScript You Don't Know
According to the definition of a memory leak, some variable or data is no longer used or needed, then it is garbage variable...
Read more >
Node.js Memory Leak Detection: How to Debug & Avoid Them
Some Node.js memory leaks are caused by common issues. These can be circular object references that are caused by a multitude of reasons....
Read more >
Effective Javascript debugging: Memory leaks | by Joao Santos
A memory leak occurs when an object that you thought would be garbage collected isn't collected because there is still at least 1...
Read more >
Memory management - JavaScript - MDN Web Docs
For instance, a JavaScript object has a reference to its prototype (implicit ... 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