Implementing Release for GNATCOLL.Refcount

GNATCOLL.Refcount provides a procedure to run some code when the reference-counted element is released.

How do I implement this procedure?

I’m clearly missing something because Release is not visible as GNATCOLL.Refcount.Release and this doesn’t work

type Context_Contents is new GNATCOLL.Refcount.Refcounted with record
    Address : System.Address;
end record;

procedure Release is new GNATCOLL.Refcount.Release
   (Self => Context_Contents);

and gives me

usb.ads:29:47: error: "Release" not declared in "Refcount"

I believe you not intended to use the ref counted object directly like that but through the Shared_Pointers generic nested package. Notice that it has an optional Release function that can be supplied as part of the shared_pointers instantiation.

I realize the error of my ways. I need to supply the release procedure as part of generic package instantiation as it’s just another argument, like element type!

Found good example here.

Take a look to these pages, if you haven’t done yet.

https://en.wikibooks.org/wiki/Ada_Programming/Generics#Generic_parameters