nitro icon indicating copy to clipboard operation
nitro copied to clipboard

Feature Request: iOS and Android dispose implementations

Open HayesGordon opened this issue 7 months ago • 3 comments

First off, amazing package. Thanks for the work!

I'm sorry if this is already possible, but I couldn't find any info on it.

The docs mention that every Hybrid Object has a dispose() method. I'm requesting that, as part of the iOS/Android protocol, you be able to implement the dispose() method. This will allow you to clean up native resources during the dispose call.

HayesGordon avatar May 16 '25 19:05 HayesGordon

I guess in this case you'd have to manually declare it in your spec. I'll think about it

mrousavy avatar May 17 '25 12:05 mrousavy

I guess in this case you'd have to manually declare it in your spec. I'll think about it

That's fine, too, as long as it doesn't prevent/override the current dispose implementation from happening.

The nice thing about exposing it on Android/iOS is that you can treat it as a finalizer, which will force users of the package to think about cleaning up anything native. Assuming that the garbage collector will always call dispose on the JS side, you can sync up the release of all your resources. For example, Java's implementation of finalization has been removed and is unreliable.

HayesGordon avatar May 17 '25 13:05 HayesGordon

For example, Java's implementation of finalization has been removed and is unreliable.

This is the exactly same in JS. That's why I'm hesitant to implement this. Objects can live for a long time before being deleted by GC. Dispose() is same as the Disposable interface in Java, additional dispose() method with weird behaviour when the user forgets it - that's why it needs IDE help so users get it.

mrousavy avatar May 17 '25 21:05 mrousavy

oh - I implemented this already in https://github.com/mrousavy/nitro/pull/770 😅

mrousavy avatar Aug 06 '25 11:08 mrousavy