Supporting circular references that can be garbage collected.
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 25/100
Línea de trabajo
Comienza con el uso de Napi::ObjectWrap y Napi::Reference mostrado en el issue y, a continuación, investiga cómo Node-API gestiona las referencias nativas y la recolección de basura para objetos que se referencian mutuamente. Se considera terminado determinar si se admiten referencias circulares recolectables y documentar o proponer el enfoque necesario a nivel de API; el issue no nombra ningún archivo fuente ni prueba.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- C++
- Estrellas
- 2.4k
- Forks
- 499
- Merge medio
- 2 d 11 h
- PR fusionados (30 d)
- 2
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de nodejs/node-addon-api
-
blocked SemVer-major
Dificultad 4/5 3-5 días Aptitud para principiantes 52/100
nodejs/node-addon-api#1748 ·
-
Support C++20 span types AbiertoSemVer-major
Dificultad 4/5 3-5 días Aptitud para principiantes 55/100
nodejs/node-addon-api#1747 · 2 comentarios ·
-
blocked SemVer-major
Dificultad 4/5 3-5 días Aptitud para principiantes 52/100
nodejs/node-addon-api#1746 ·
-
SemVer-major
Dificultad 4/5 3-5 días Aptitud para principiantes 55/100
nodejs/node-addon-api#1745 ·
-
stale
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
nodejs/node-addon-api#1724 · 2 comentarios ·
Todos los issues de nodejs/node-addon-api
Issues similares
-
Website Doc Typo Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 92/100
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 92/100
autowarefoundation/autoware_universe#13413 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
-
automated-analysis bug memory-safety
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100