Hi,

We developing a D dll (v 2.060) called (pinvoked) by a C# client. The DLL is responsible for filtering large amounts of data. It consists of some functions (for example GetRetailSale below), which filters the data based on some criteria (defined in state). The cached list consists of about 500000 items (ExtendedOrderItemDTO) and when we use a search criteria that results in a large amount of items we get a memory leak of about 90MB on each run. With results containing fewer items, there seems to be no leak at all.

The cached list of orderitems (Cache.OrderItems), is shared and is initialized when the dll is first loaded and is then never modified.

Any ideas?


public static shared class Cache
{
  private static shared ExtendedOrderItemDTO[] _orderItems;
  public static @property ExtendedOrderItemDTO[] OrderItems()
  {
    return cast(ExtendedOrderItemDTO[]) _orderItems;
  }
}


export extern(C) wchar* GetRetailSale(State state, bool includeZeroResults)
{
ExtendedOrderItemDTO[] retailersOrderItems=GetRetailersOrderItems(state);
  // code...
  return toUTFz!(wchar*)(message);
}

public ExtendedOrderItemDTO[] GetRetailersOrderItems(State state)
{
        auto result=filter!( (ExtendedOrderItemDTO x) =>
          x._SaleDate >= state.StatePeriod.From &&
          x._SaleDate <= state.StatePeriod.To &&
          (
          state.Brand.Level == 0 ||
          (state.Brand.Level == 1 && state.Brand.ID == x.BrandID) ||
          (state.Brand.Level == 2 && state.Brand.ID == x.VariantID) ||
          (state.Brand.Level == 3 && state.Brand.ID == x.ProductID)
        ) &&
        (
          state.Channel.Level == 0 ||
          (state.Channel.Level == 1 && state.Channel.ID == x.Channel) ||
          (state.Channel.Level == 2 && state.Channel.ID == x.SubChannel)
        ) &&
        (
          state.ProductType == 2 ||
          (state.ProductType == 0 && x.IsFMC == true) ||
          (state.ProductType == 1 && x.IsFMC == false)  
        )
        )(Cache.OrderItems);

        return array(result);
}

public struct ExtendedOrderItemDTO
{
        public int ID;
        public eInvoiceType InvoiceType;
        public long VirtualStickCount;
        public wchar* Currency;
        public wchar* SaleDate;
        public double Price;

        public long ProductID;
        public bool IsFMC;

        public long PointOfSaleID;

        public int RetailerID;
        public int SubRetailerID;

        public int Channel;
        public int SubChannel;

        public int BrandID;
        public int VariantID;
        
        public Date _SaleDate;
}

Reply via email to