Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
277 views
in Technique[技术] by (71.8m points)

javascript - Firefox Memory Leak after Retrieving Data from IndexedDB

I have (what appear to be) numerous memory leaks in my Firefox Add-on, but let's focus on the biggest.

I retrieve my local IndexedDB and store it into a variable. The reason for this is that searching the database can currently take over a minute per search if using a cursor instead of a supported IDBKeyRange, and storing the data in memory at start-up would make it much faster:

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;
}

Currently, the only thing my add-on is doing is opening a database and retrieving results. I have stopped every other function call to focus on this issue. This results in about 2.5 GB of memory usage. Regardless of what I do, however, that memory usage NEVER decreases; it only goes UP. So if I need to call getData() again for whatever reason, my memory usage goes up to around 4 GB and then crashes the add-on.

Setting data = null; does nothing to help.

I've run the database query with Web Workers and also using openCursor() instead of getAll() in case the database was somehow the issue. That didn't change the end result.

I tried running the Firefox garbage collector in about:memory to verify it just wasn't being slow in the add-on. Nothing.

Can anyone help me figure this out?

Here are the memory results for the add-on:

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)
question from:https://stackoverflow.com/questions/65865969/firefox-memory-leak-after-retrieving-data-from-indexeddb

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...