java.lang.ref.Cleaner Added in API level 33 How/Where to use it in android and it is usfule to avoid leaking

Viewed 23

I need to ask some questions about this new class added recently in API 33, When should I use this class to clean resources? and It is usful to avoid memory leaking that could happen on some resources? If there's a small example of usage in android I'll be appreciated

Cleaner

Cleaning actions are registered to run after the cleaner is notified that the object has become phantom reachable. The cleaner uses PhantomReference and ReferenceQueue to be notified when the reachability changes.

Each cleaner operates independently, managing the pending cleaning actions and handling threading and termination when the cleaner is no longer in use. Registering an object reference and corresponding cleaning action returns a Cleanable. The most efficient use is to explicitly invoke the clean method when the object is closed or no longer needed. The cleaning action is a Runnable to be invoked at most once when the object has become phantom reachable unless it has already been explicitly cleaned. Note that the cleaning action must not refer to the object being registered. If so, the object will not become phantom reachable and the cleaning action will not be invoked automatically.

0 Answers
Related