Memory usage keeps increasing as test runs

I have a UVM tb that keeps increasing memory usage the longer I run it. The test does finish. I have determined the leak to come from the driver because when I test it without driving an item, only generating it, the memory usage is very small. This turns into issues when I run larger tests as it crashes the computer.

I have tested commenting out the monitor thinking maybe that is the issue but the memory usage is the same. So that has led me to believe it is the driver causing the memory issue.

Below is my drive_item from my driver.

virtual task drive_item(Item_in m_item);
      if (dut_in1.rst_n) begin
         @(posedge dut_in1.clk);
         dut_in1.data <= 'x;
         dut_in1.empty_b <= 'x;
         dut_in1.valid <= 0;
         dut_in1.eop <= 0;
         dut_in1.sop <= 0;
         empty = (DATA_BYTES - (m_item.data_in.size() % DATA_BYTES));
         count = 0;
         do begin
            if (!dut_in1.valid | dut_in1.ready) begin
               if (count + DATA_BYTES >= m_item.data_in.size()) begin
                  dut_in1.eop <= 1;
                  if (contains(my_name, "dma_in") | contains(my_name, "tcp_in")) begin
                     flag = 0;
                     dut_in1.error_r <= 1'b0;
                  end else begin
                     flag = m_item.error_r ? 1 : 0;
                     dut_in1.error_r <= m_item.error_r;
                  end
               end else begin
                  dut_in1.eop <= 0;
                  dut_in1.error_r <= 0;
                  flag = 0;
               end
               dut_in1.session_id_in = m_item.session_id;
               dut_in1.sop <= (count == 0);
               dut_in1.empty_b <= (count + (m_item.data_in.size() % DATA_BYTES) >= m_item.data_in.size()) ? empty : 0;
               dut_in1.valid <= 1;
               dut_in1.payload_size <= m_item.data_in.size();
               for (int i = 0; i < DATA_BYTES; i++) begin
                  if (count < m_item.data_in.size()) begin
                     dut_in1.data[(DATA_BYTES*8-1)-(8*i)-:8] <= flag ? 'X : m_item.data_in[count];
                     count += 1;
                  end
               end
            end
            @(posedge dut_in1.clk);
         end while (!(dut_in1.ready & dut_in1.valid & dut_in1.eop));
         m_item.data_in.delete(); //Added this thinking maybe its because the data isn't being deleted.
         dut_in1.empty_b <= 'x;
         dut_in1.valid <= 0;
         dut_in1.eop <= 0;
         dut_in1.sop <= 0;
         dut_in1.payload_size <= 'x;
      end else begin
         @(posedge dut_in1.clk);
      end

   endtask```

There is nothing in the code shown that points to a memory leak. It’s possible the problem is in the code that calls drive_item. I suggest looking at your tool’s profiling capabilities. Check the number of class instances as time progresses.

Hi Dave, thanks for the answer.

This is where I call the drive_item from.

   Item_in m_item;

   virtual task run_phase(uvm_phase phase);
      super.run_phase(phase);
      #1500;
      forever begin
         seq_item_port.get_next_item(m_item);
         `uvm_info("DRV_IN", $sformatf("Received Item_in from Sequencer_in"), UVM_HIGH)
         drive_item(m_item);
         seq_item_port.item_done();
      end
   endtask

When I comment out the drive_item(m_item) call, it seems to not leak memory.

I am looking into Vivado profiling tools as well.

When printing out the instance count using the UVM function, get_inst_count() and get_inst_id()

(I added this print out after the drive_item(m_item) call as seen above)

get_type_name = uvm_driver #(REQ,RSP) , get_inst_count = 12278, get_inst_id = 1178
get_type_name = uvm_driver #(REQ,RSP) , get_inst_count = 12278, get_inst_id = 1376
get_type_name = uvm_driver #(REQ,RSP) , get_inst_count = 16628, get_inst_id = 1178
get_type_name = uvm_driver #(REQ,RSP) , get_inst_count = 16628, get_inst_id = 1376
get_type_name = uvm_driver #(REQ,RSP) , get_inst_count = 20988, get_inst_id = 1178
get_type_name = uvm_driver #(REQ,RSP) , get_inst_count = 20988, get_inst_id = 1376
get_type_name = uvm_driver #(REQ,RSP) , get_inst_count = 25348, get_inst_id = 1178
get_type_name = uvm_driver #(REQ,RSP) , get_inst_count = 25348, get_inst_id = 1376
get_type_name = uvm_driver #(REQ,RSP) , get_inst_count = 29694, get_inst_id = 1178
get_type_name = uvm_driver #(REQ,RSP) , get_inst_count = 29694, get_inst_id = 1376
get_type_name = uvm_driver #(REQ,RSP) , get_inst_count = 34054, get_inst_id = 1178
get_type_name = uvm_driver #(REQ,RSP) , get_inst_count = 34054, get_inst_id = 1376
get_type_name = uvm_driver #(REQ,RSP) , get_inst_count = 38414, get_inst_id = 1178
get_type_name = uvm_driver #(REQ,RSP) , get_inst_count = 38414, get_inst_id = 1376
get_type_name = uvm_driver #(REQ,RSP) , get_inst_count = 42758, get_inst_id = 1178
get_type_name = uvm_driver #(REQ,RSP) , get_inst_count = 42758, get_inst_id = 1376
get_type_name = uvm_driver #(REQ,RSP) , get_inst_count = 47120, get_inst_id = 1178
get_type_name = uvm_driver #(REQ,RSP) , get_inst_count = 47120, get_inst_id = 1376
get_type_name = uvm_driver #(REQ,RSP) , get_inst_count = 51480, get_inst_id = 1178
get_type_name = uvm_driver #(REQ,RSP) , get_inst_count = 51480, get_inst_id = 1376
get_type_name = uvm_driver #(REQ,RSP) , get_inst_count = 55824, get_inst_id = 1178
get_type_name = uvm_driver #(REQ,RSP) , get_inst_count = 55824, get_inst_id = 1376
get_type_name = uvm_driver #(REQ,RSP) , get_inst_count = 60184, get_inst_id = 1178
get_type_name = uvm_driver #(REQ,RSP) , get_inst_count = 60184, get_inst_id = 1376
get_type_name = uvm_driver #(REQ,RSP) , get_inst_count = 64546, get_inst_id = 1178
get_type_name = uvm_driver #(REQ,RSP) , get_inst_count = 64546, get_inst_id = 1376
get_type_name = uvm_driver #(REQ,RSP) , get_inst_count = 68906, get_inst_id = 1178
get_type_name = uvm_driver #(REQ,RSP) , get_inst_count = 68906, get_inst_id = 1376
get_type_name = uvm_driver #(REQ,RSP) , get_inst_count = 73250, get_inst_id = 1178
get_type_name = uvm_driver #(REQ,RSP) , get_inst_count = 73250, get_inst_id = 1376

I see the inst_count keep increasing throughout the entire simulation.

An increasing instance count is expected with any transaction object. You need to know how many of those transactions are active/allocated at any given time. You need information from your simulator to tell you that.

I am using vivado xsim and don’t think those features are available. Thanks for your answers anyway!