アンマネージドアプリからマネージドアプリへのプロセス間データ交換用のシンプルな共有メモリ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);        
     }
}