Try placing the access variable inside the protected type: package Managed_Allocation is type Node is private; function New_Node return Node; private type Node_Data is record Reference_Count : Natural := 0; end record; type Node_Data_Access is access all Node_Data; type Node is new Ada.Finalization.Controlled with record Node_Data_Ref : Node_Data_Access; end record; procedure Initialize ( Object : in out Node ); procedure Adjust ( Object : in out Node ); procedure Finalize ( Object : in out Node ); end Managed_Allocation; with Ada.Unchecked_Deallocation; package body Managed_Allocation is function New_Node return Node is Data_Node : Node; begin Data_Node.Node_Data_Ref := new Node_Data; return Data_Node; end New_Node; procedure Free is new Ada.Unchecked_Deallocation( Node_Data, Node_Data_Access ); procedure Initialize ( Object : in out Node ) is begin Object .Node_Data_Ref := null; end Initialize; procedure Adjust ( Object : in out Node ) is begin if Object .Node_Data_Ref /= null then Object.Node_Data_Ref.Reference_Count := Object .Node_Data_Ref. Reference_Count + 1; end if; end Adjust; procedure Finalize ( Object : in out Node ) is begin if Object.Node_Data_Ref /= null then Object.Node_Data_Ref.Reference_Count := Object.Node_Data_Ref. Reference_Count - 1; if Object .Node_Data_Ref.Reference_Count = 0 then Free( Object .Node_Data_Ref ); Object .Node_Data_Ref := null; end if; end if; end Finalize; end Managed_Allocation; BTW: I didn't check, but you can probably find another example of this at: www.adapower.com SteveD "Preben Randhol" wrote in message news:slrn9e2vqb.aah.randhol+abuse@kiuk0156.chembio.ntnu.no... > > Hi > > I'm wondering if it is possible to do something like this > > type Data_Type is new Ada.Finalization.Controlled with > record > References: Integer := 0; > end record; > > type Data_Access_Type is access Data_Type; > > [..] > > and then in the main program if I do something like this: > > procedure main is > > Pointer : Data_Access_Type := null; > Data : Data_Access_Type := new Data_Type; > > begin > > Pointer := Data; > > end main; > > to have Data.References increases by using Adjust? I'm trying but it > looks like it only works if I do: > > Pointer : Data_Type; > ... > Pointer := Data.all; > ... > otherwise Adjust is not invoked. Is it possible to get it invoked if one > point an access type to an object? I'm trying to eliminate the problem > of dangling pointers in a program... > > Thanks in advance. > > -- > Preben Randhol ------------------- http://www.pvv.org/~randhol/ -- > �For me, Ada95 puts back the joy in programming.�