Lifetime issue with JS + NPAPI amounts a bit to black magic, since it mixes garbage collection and reference-counting.
The object can only be deleted if both of these are true:
- Javascript doesn't have any more reference to it and garbage-collects it
- The NPAPI ref count falls to 0.
Note 2 things however:
- I don't think your 'delete nc' line does anything. 'delete' is used to remove properties from objects, not to force-delete objects. If anything, it would delete the *reference* (ie the remove the variable nc from the scope), not the object itself.
- the Javascript interpreter doesn't have to run the garbage collector in a timely fashion, which means the objects may not be destroyed immediately.
In a nutshell, you unfortunately don't have any way to ensure that an object is destroyed. We worked around the problem in o3d by making the Javascript references "weak", and have a separate mechanism ("packs") to ensure lifetime, so that we could release system resources (e.g. GPU memory) in a timely fashion.
Antoine