Kodein cleanup/destroy method

1k Views Asked by At

I'm using kodein (Kodein.global variant) for my LibGDX project. A lot of LibGDX objects have their own cleanup methods (dispose and Disposable interface) which are called after the object is no longer in use and ready for GC cleanup (when switching screens, exiting, etc..). I would like for these calls to be done when kodein performs its cleanup.

I've skimmed through the Kodein documentation but I was not able to find any reference to a cleanup method, something like Java EE @PreDestroy or Spring bean destroy-method method.

Does Kodein not have this sort of feature or am I missing something?

1

There are 1 best solutions below

1
On

Kodein offers the "scope closeable" feature.

However, it only works on scope that supports it, and there are no such scopes provided by the library outside of the Android scope.

Have a look at http://kodein.org/Kodein-DI/?5.2/core#scope-closeable ;)

Outside of a scope expiring, there are no ways for Kodein to know when a particular object's lifecycle would expire.