/
spirzen
/
it-code-examples
Обзор
Документация
Войти
/
spirzen
/
it-code-examples
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/javascript/js-501-22-050/main.js
28 строк
783 B
Spirzen
Code migration pack
09 июн 2026, 01:41
09 июн 2026, 01:41
cebc284
Код
Авторство
О чём код?
const registry = new FinalizationRegistry(heldValue => { console.log(`Объект освобождён: ${heldValue}`); }); class Resource { constructor(name) { this.name = name; this.buffer = new ArrayBuffer(1024 * 1024); // 1 МБ registry.register(this, name, this); } cleanup() { registry.unregister(this); console.log(`Ресурс ${this.name} очищен вручную`); } } // Создание ресурса const resource1 = new Resource("файл1"); const resource2 = new Resource("файл2"); // Удаление ссылок resource1 = null; resource2.cleanup(); resource2 = null; // Через некоторое время в консоли: // "Объект освобождён: файл1"