Supporting circular references that can be garbage collected.
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 5/5
- Tempo estimado
- Mais de uma semana
- Facilidade para iniciantes
- 25/100
Direção de pesquisa
Comece com o uso de Napi::ObjectWrap e Napi::Reference mostrado na issue e, em seguida, investigue como a Node-API lida com referências nativas e coleta de lixo para objetos que fazem referência mútua. O trabalho estará concluído quando for estabelecido se referências circulares coletáveis são compatíveis e a abordagem necessária no nível da API for documentada ou proposta; a issue não nomeia nenhum arquivo-fonte nem teste.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
- Linguagem predominante
- C++
- Estrelas
- 2.4k
- Forks
- 499
- Merge médio
- 2d 11h
- PRs com merge (30d)
- 2
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de nodejs/node-addon-api
-
blocked SemVer-major
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 52/100
nodejs/node-addon-api#1748 ·
-
Support C++20 span types AbertaSemVer-major
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 55/100
nodejs/node-addon-api#1747 · 2 comentários ·
-
blocked SemVer-major
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 52/100
nodejs/node-addon-api#1746 ·
-
SemVer-major
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 55/100
nodejs/node-addon-api#1745 ·
-
stale
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 48/100
nodejs/node-addon-api#1724 · 2 comentários ·
Todas as issues de nodejs/node-addon-api
Issues semelhantes
-
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 92/100
autowarefoundation/autoware_universe#13413 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100
-
automated-analysis bug memory-safety
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 86/100
-
Sensor initialization takes very long when `--initial-sim-time` is set to current UNIX timestamp Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
gazebosim/gz-sensors#662 · 1 comentário ·