then usage of the resources should happen with try-with-resources which ensures their closing
try (final SomeClass sc = new SomeClass("perhaps arg").open()) { // allocates memory, open returns allocated instance of the class
System.out.println("you have call()ed and it provides you with " + sc.something());
} // frees it because close is automatically done
care must be taken that SomeClass methods are blocked while allocation is not done, for example with AtomicBoolean and if not the thr IllegalStateException
change the Java classes to use AutoCloseable interface so that pointers get automatically freed
see https://www.yegor256.com/2017/08/08/raii-in-java.html
then usage of the resources should happen with try-with-resources which ensures their closing
try (final SomeClass sc = new SomeClass("perhaps arg").open()) { // allocates memory, open returns allocated instance of the class System.out.println("you have call()ed and it provides you with " + sc.something()); } // frees it because close is automatically done
care must be taken that SomeClass methods are blocked while allocation is not done, for example with AtomicBoolean and if not the thr IllegalStateException
see also https://stackoverflow.com/a/69444249