Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I avoid state of "TypeError: can't access dead object" in my Firefox add-on?

It seems checking against null works, but is it a correct method? How can I correctly check that object is not dead? And where is the definition of dead object?

like image 769
rlib Avatar asked Oct 20 '22 04:10

rlib


1 Answers

This is likely due to holding zombie compartments. If you are storing a window in a variable you should use weak reference, otherwise it will keep the process alive.

Great read right here:

https://developer.mozilla.org/en-US/docs/Zombie_compartments

This is how to use weak references: https://developer.mozilla.org/en-US/docs/Components.utils.getWeakReference

A dead object, is holding a strong (keep alive) reference to a DOM element (usually) that persists even after it was destroyed in the DOM.

Sometimes checking if it is undefined or null does not work, a trick I saw once and use sometimes is to check if parentNode exists (so not null or undefined).

like image 80
Blagoh Avatar answered Oct 23 '22 02:10

Blagoh