Problem with the associative array with queue (not taking data corrrectly)

as i am randomizing handle for 5 times 5 different address are generated but when displaying the queue it is printing the same address value genetared at that transaction.push back is not working …

class demo;
  rand bit[3:0] addr;
  bit [2:0] index=2;
endclass
class memory;
  demo mem[int][$];
endclass
module top;
   memory mem_h;
  
  demo d1,d2;
  initial begin 
      mem_h= new();
     d1=new();
    d2=new();
    repeat(5)
      begin 
        assert (d2.randomize());
        mem_h.mem[d1.index].push_back(d2);
        $display("value of q=%p,mem_address =%d",mem_h.mem,mem_h);
      end
  end
endmodule

output

value of q='{2:'{'{addr:2, index:2}}},mem_address =                        139819985821116
# KERNEL: value of q='{2:'{'{addr:5, index:2}, '{addr:5, index:2}}},mem_address =                        139819985821116
# KERNEL: value of q='{2:'{'{addr:10, index:2}, '{addr:10, index:2}, '{addr:10, index:2}}},mem_address =                        139819985821116
# KERNEL: value of q='{2:'{'{addr:4, index:2}, '{addr:4, index:2}, '{addr:4, index:2}, '{addr:4, index:2}}},mem_address =                        139819985821116
# KERNEL: value of q='{2:'{'{addr:2, index:2}, '{addr:2, index:2}, '{addr:2, index:2}, '{addr:2, index:2}, '{addr:2, index:2}}},mem_address =

In reply to rahulraoece:
Please use code tags making your code easier to read. I have added them for you.

You are pushing the same handle (d2) to the queue, so all queue entries have the same value. You need to move the construction of d2 into the loop.

initial begin 
    mem_h= new();
    d1=new();
    repeat(5)
      begin 
        d2=new();
        assert (d2.randomize());
        mem_h.mem[d1.index].push_back(d2);
        $display("value of q=%p,mem_address =%d",mem_h.mem,mem_h);
      end
  end

In reply to dave_59:

In reply to rahulraoece:
Please use code tags making your code easier to read. I have added them for you.
You are pushing the same handle (d2) to the queue, so all queue entries have the same value. You need to move the construction of d2 into the loop.

initial begin 
mem_h= new();
d1=new();
repeat(5)
begin 
d2=new();
assert (d2.randomize());
mem_h.mem[d1.index].push_back(d2);
$display("value of q=%p,mem_address =%d",mem_h.mem,mem_h);
end
end

its working ,thank you…