我有简单的共享内存 DLL,用于从非托管应用程序到托管应用程序的进程间数据交换。而且我注意到我的托管应用程序内存的大小正在稳步增长。有人可以建议可能是什么原因,如何找到它以及如何解决它?以下代码的相关部分。
cpp SharedMem.DLL:
#pragma data_seg( ".IPC" )
....
double darr[MAXITEMS] = { 0.0 } ; 
....
#pragma data_seg()
....
double __stdcall MGetDouble (int idx)
{
    if ( idx>= 0 && idx < MAXITEMS)
    {
        return darr[idx]; 
    }
    else
    {
        return -1.0 ; 
    }
}
int __stdcall MSetDouble (int idx, double dvalue)
{
    if ( idx>= 0 && idx< MAXITEMS)
    {
        darr[idx] = dvalue;
        return idx;
    }
    else
    {
        return -1;
    }
}
和 c# 应用程序:
[DllImport("SharedMem.DLL", CallingConvention = CallingConvention.StdCall)]
public static extern double MGetDouble(int index);
....
private void timer1_Tick(object sender, EventArgs e)
{
    ThreadPool.QueueUserWorkItem(dosmth);
}
public object lockobj = new object();
public void dosmth(object o)
{
    if (Monitor.TryEnter(lockobj, 50))
    {
        ....
        double[,] matrix = new double[size, TSIZE];
        ....
        double gvd;
        int k;
        for (int i = 0; i < lines; i++)
            for (j = 0; j < TSIZE; j++) 
            {
                k++; //k can be up to 2k-4k typically
                gvd = MGetDouble(k);
                matrix[i, j] = gvd;
            }
            //... do the stuff
         Monitor.Exit(lockobj);        
     }
}