Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Explicit Resource Management to proxy object #91

Closed
sla100 opened this issue Nov 10, 2023 · 1 comment
Closed

Add Explicit Resource Management to proxy object #91

sla100 opened this issue Nov 10, 2023 · 1 comment

Comments

@sla100
Copy link
Contributor

sla100 commented Nov 10, 2023

Is your feature request related to a problem? Please describe.

It is important to release proxy object when no longer in use. Ex.

const proxy = java.newProxy(...);
try {
  // operations ... 
} finally {
  proxy.reset();
}

Typescript 5.2 and Node 20 introduced a new approach known e.g. in Java as try-resource:

using proxy = java.newProxy(...);
// operations ... 
proxy.reset();

Describe the solution you'd like

The implementation requires adding an Symbol.dispose alias for the reset method in the proxy object.

Additional context

https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html#using-declarations-and-explicit-resource-management

https://tc39.es/proposal-explicit-resource-management/

@sla100 sla100 changed the title Add Symbol.dispose to proxy Add Explicit Resource Management to proxy object Nov 10, 2023
@MarkusJx
Copy link
Owner

No, it's not strictly necessary to call reset on a JavaInterfaceProxy. The inner proxy instance is already automatically destroyed once the garbage collector cleans up the JavaInterfaceProxy instance. Calling reset on the instance only speeds up the process as the garbage collector only runs in intervals. This is important if you want your application to exit as fast as possible as any existing interface proxies will prevent your application from closing (although process.exit() will stop the application instantly).

This is kind of documented in the notes of newProxy, but I see where the confusion is coming from. I'll try to clarify this behavior in the docs (in #92).

Closing this issue as this is already implemented and the current implementation doesn't require a new node.js version.

@MarkusJx MarkusJx closed this as not planned Won't fix, can't repro, duplicate, stale Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants