Supporting circular references that can be garbage collected.
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 25/100
Direzione di ricerca
Inizia con l’uso di Napi::ObjectWrap e Napi::Reference mostrato nell’issue, quindi analizza come Node-API gestisce i riferimenti nativi e la garbage collection per oggetti che si referenziano reciprocamente. Il lavoro è completato quando si è stabilito se i riferimenti circolari raccoglibili sono supportati e si è documentato o proposto l’approccio necessario a livello di API; l’issue non indica alcun file sorgente né alcun test.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
In JavaScript I can make two objects that reference each other and they'll still be GCed.
function makeObjectsThatReferenceEachOtherButLeakNoReferences() {
const a = new Uint8Array(1024);
const b = new Uint8Array(1024);
a.other = b; // make them reference each other
b.other = a;
}
makeObjectsThatReferenceEachOtherButLeakNoReferences();
In the code above, even though a circular reference was created, JavaScript will see there is no path from root and garbage collect the objects.
Is it possible to do the same in C++ Napi. If I make a class
class MyClass : public Napi::ObjectWrap<MyClass> {
...
Napi::Reference<Napi::Object> storedObjectRef_;
};
And I manage to make 2 instanced of MyClass and set storedObjectRef_ so they point to each other, AFAICT these objects will never be garbage collected.
Is there a solution?
Note: I know I could add some function close or whatever to null out storedObjectRef_ but that's not really the question I'm asking. I'm trying to reproduce JS garbage collecting circular references.
One idea I guess, which appears to work, is I could add a JS property to MyClass. So instead of Napi::Reference<Napi::Object> storageObjectRef_ I'd use Get, Set as in
this->Value().Set("storageObjectRef", otherObject);
but unfortunately that's visible externally which I don't want. I could use a symbol but those are inspectable too. Though it might be better than nothing if there is no other solutions.
- Lingua principale
- C++
- Stelle
- 2.4k
- Fork
- 499
- Merge medio
- 2g 11h
- PR unite (30g)
- 2
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di nodejs/node-addon-api
-
blocked SemVer-major
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
nodejs/node-addon-api#1748 ·
-
Support C++20 span types ApertaSemVer-major
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
nodejs/node-addon-api#1747 · 2 commenti ·
-
blocked SemVer-major
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
nodejs/node-addon-api#1746 ·
-
SemVer-major
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
nodejs/node-addon-api#1745 ·
-
stale
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
nodejs/node-addon-api#1724 · 2 commenti ·
Tutte le issue di nodejs/node-addon-api
Issue simili
-
Website Doc Typo Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 92/100
autowarefoundation/autoware_universe#13413 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
automated-analysis bug memory-safety
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100