Object lifetime Island Windows

What is the secure way to manage the Object Lifetime from a object in island/windows?
Let’s say I have a class that wraps an external resource.
Now I wan’t an automatic cleanup if this object goes out of scope.
I can write a method and call it, or should I write the classes as IDisposable and
and do something like

Using ctx := new Context(....) do begin
// Use the ctx
end;

This seems to work. Is it the right way? And if I use “Using” the compiler does not flag a error if the class is not a IDisposable, is this correct?

right; using doesn’t flag it. It does something like IDisposable(ctx):Dispose; in a finally, that way you can have classes that ARE and AREN’T Disposable and still have it work. Above is the best way to do that yes.

2 Likes