Skip to content

Request to Contribute: Improving Memory Management and Sustanibility of the project with clean code #39

@PanagiotisDrakatos

Description

@PanagiotisDrakatos

I hope this message finds you well. I am very interested in contributing to your open-source project because it is mandatory for my crypto project. I would like to know if the project is still actively maintained and I believe I can contribute to some areas where you could use additional help.

For example, I see some ugly, eyesores and unsightly things in the code that is killer for the sustainability and memory management of the project and need to be redefined because these actions are dangerous and can cause a lot of trouble.

//This code should be prohibited 
    @Override
    protected void finalize() {
        LibGMP.__gmpz_clear(peer);
        try {
            super.finalize();
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }

The dispose() function is essential for safely destructing objects and is recommended by the public JNA library. Never Never use finalize(). In addition, finalize is deprecated for java 9 and later because it's a killer for the program's health.

//This code should be replaced.
public class LibLoader {
    private NativeLibrary lib;

    public void load() {
        lib = NativeLibrary.getInstance("mylib");
    }

    public void cleanup() {
        if (lib != null) {
            lib.dispose(); // Release native resources
            lib = null;
        }
        clearJNACache();
    }

    private void clearJNACache() {
        try {
            Field librariesField = NativeLibrary.class.getDeclaredField("libraries");
            librariesField.setAccessible(true);
            ((Map<?, ?>) librariesField.get(null)).clear();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Please let me know if there are extra or any specific tasks or issues you would like assistance with and if I am eligible to contribute to the project.

Thank you for your time, and I look forward to the possibility of collaborating with you.

Best regards,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions