You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered: