I’m fairly sure the answer is “no” – you can’t hook into the JS garbage collection process in the same way that you can with Java’s finalizers (or
Can you instead deal with this more declaratively? Your question seems to imply that the only way your system “knows” when a file is no longer needed, is when it is GCed (or in other words, your system doesn’t know at all). Are you really referencing these files all over the application? Good practice would be for these resources to be used with a well-defined lifecycle, such that the part of the system that creates a temp file is also responsible for destroying it after it’s finished with it.
Under that model, when you (explicitly) destroy the file in JS, you can call back to Java to perform the required clean up.
Releasing a resource by simply removing all references to it, as you’re doing at the moment, is not particularly good practice.