Skip to content

change malloc/free pairs to use AutoCloseable #21

@kortemik

Description

@kortemik

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

Metadata

Metadata

Assignees

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