从 IndexedDB 检索数据后 Firefox 内存泄漏

问题描述

我的 Firefox 附加组件中有(似乎是)大量内存泄漏,但让我们关注最大的。

我检索我的本地 IndexedDB 并将其存储到一个变量中。这样做的原因是,如果使用游标而不是受支持的 IDBKeyRange,搜索数据库目前每次搜索可能需要超过一分钟,并且在启动时将数据存储在内存中会使其更快:

var db = My Indexed Database;  // I open the database elsewhere
var index = "whatever";
var dbName = "something";
var data;

getData(index);

data = null;

function getData(index) {
    let get = db.transaction(dbName).objectStore(name).index(index).getAll(iDBRange);
    get.onsuccess = e => data = e.target.result;
}

目前,我的插件唯一要做的就是打开数据库并检索结果。我已经停止了所有其他函数调用以专注于这个问题。这会导致大约 2.5 GB 的内存使用量。然而,无论我做什么,内存使用量都不会减少;它只会上升。因此,如果我出于某种原因需要再次调用 getData(),我的内存使用量会上升到 4 GB 左右,然后会导致加载项崩溃。

设置 data = null; 没有任何帮助。

我已经使用 Web Workers 运行了数据库查询,并且还使用了 openCursor() 而不是 getAll(),以防数据库以某种方式出现问题。这并没有改变最终结果。

我尝试在 about:memory 中运行 Firefox 垃圾收集器,以验证它在附加组件中并没有变慢。没什么。

谁能帮我解决这个问题?

以下是插件的内存结果:

extension (pid 37752)
Explicit Allocations

2,466.70 MB (100.0%) -- explicit
├──2,015.47 MB (81.71%) -- window-objects
│  ├──2,013.26 MB (81.62%) -- top(moz-extension://d804a8ce-f442-44a5-a7c1-b54dd441a7d2/background.html,id=113)
│  │  ├──1,651.84 MB (66.97%) -- js-zone(0xdbbd000)
│  │  │  ├──1,635.54 MB (66.30%) -- strings
│  │  │  │  ├──1,539.12 MB (62.40%) -- string(<non-notable strings>)
│  │  │  │  │  ├──1,462.24 MB (59.28%) -- malloc-heap
│  │  │  │  │  │  ├────916.53 MB (37.16%) ── two-byte
│  │  │  │  │  │  └────545.71 MB (22.12%) ── latin1
│  │  │  │  │  └─────76.87 MB (03.12%) -- gc-heap
│  │  │  │  │        ├──67.57 MB (02.74%) ── latin1
│  │  │  │  │        └───9.30 MB (00.38%) ── two-byte
│  │  │  │  └─────96.42 MB (03.91%) ++ (4111 tiny)
│  │  │  └─────16.30 MB (00.66%) ++ (10 tiny)
│  │  └────361.42 MB (14.65%) -- active/window(moz-extension://d804a8ce-f442-44a5-a7c1-b54dd441a7d2/background.html)
│  │       ├──361.30 MB (14.65%) -- js-realm(moz-extension://d804a8ce-f442-44a5-a7c1-b54dd441a7d2/background.html)
│  │       │  ├──361.00 MB (14.63%) -- classes
│  │       │  │  ├──205.14 MB (08.32%) -- class(Object)/objects
│  │       │  │  │  ├──196.00 MB (07.95%) -- malloc-heap
│  │       │  │  │  │  ├──191.77 MB (07.77%) ── slots
│  │       │  │  │  │  └────4.23 MB (00.17%) ── elements/normal
│  │       │  │  │  └────9.14 MB (00.37%) ── gc-heap
│  │       │  │  ├──145.39 MB (05.89%) ── class(Date)/objects/gc-heap
│  │       │  │  └───10.47 MB (00.42%) ++ (6 tiny)
│  │       │  └────0.30 MB (00.01%) ++ (4 tiny)
│  │       └────0.12 MB (00.01%) ++ (3 tiny)
│  └──────2.21 MB (00.09%) ++ (6 tiny)
├────177.82 MB (07.21%) -- dmd
│    ├──176.00 MB (07.14%) ── live-block-table
│    └────1.82 MB (00.07%) ++ (2 tiny)
├────138.87 MB (05.63%) -- heap-overhead
│    ├───96.08 MB (03.89%) -- bin-unused
│    │   ├──51.56 MB (02.09%) ++ (33 tiny)
│    │   └──44.51 MB (01.80%) ── bin-2048
│    ├───42.20 MB (01.71%) ── bookkeeping
│    └────0.59 MB (00.02%) ── page-cache
├────101.47 MB (04.11%) ── profiler/profiler-state
├─────25.73 MB (01.04%) ++ js-non-window
└──────7.36 MB (00.30%) ++ (22 tiny)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)