Issue
In my JavaFX application, at a specific page I have to initialize (when loading the page) some devices such as iris scanner, fingerprint scanner, cameras etc. Before leaving the page/controller it is necessary to deinitialize the devices. There are two buttons in that page. If the user leaves this page by clicking one of these two buttons I can easily deinitialize them. But if the user leaves the page by clicking any menu/sub menu (there are more than 30 menu and sub menu in this application), how can I deinitialize these devices?
There is no destructor in java and I also tried using finalize
but nothing comes out.
Solution
You cannot rely only on the finalize()
method. An answer to this request seems to show that this method is used by the garbage collector to check data loss references. So you need to destroy objects by-hand in a custom method, then finalize()
will be automatically applied.
You must create a deinitialize()
method (public or package-private, depends on the location of your MenuBar controller) then call it inside your sub-menu item.
Answered By - 0009laH
Answer Checked By - Candace Johnson (JavaFixing Volunteer)