Interop Memory Problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bbembi_de@lycos.de

    Interop Memory Problem

    Hello,

    I use a C++ Dll in .Net 1.1 with Dllimport.
    I call one C++ method in a loop and the memory of my .Net application
    rises proportional.

    What am I doing wrong calling this method?

    Simplified it's like this:

    [StructLayout(La youtKind.Sequen tial)]
    public struct MyStruct {
    [MarshalAs(Unman agedType.LPStr)] public string name;
    public int media;
    }

    Test 1:

    [DllImport("Tool kitApiDll.dll", ExactSpelling=t rue)]
    public static extern int GetData(IntPtr mystruct);

    IntPtr ptr = Marshal.AllocHG lobal(Marshal.S izeOf(typeof(My Struct)));
    GetData(ptr);
    MyStruct m = (MyStruct) Marshal.PtrToSt ructure(ptr, typeof(MyStruct ));
    GetData(ptr);
    Marshal.FreeHGl obal(ptr);


    Test 2:

    [DllImport("Tool kitApiDll.dll", ExactSpelling=t rue)]
    public static extern int GetData(ref MyStruct mystruct);

    MyStruct m = new MyStruct();
    GetData(ref m);


    Both ways I get the data but the memory rises.

    Any ideas?
    Thanks.

    bye bembi

  • Mattias Sjögren

    #2
    Re: Interop Memory Problem


    Are you sure the mempry leak (if there is one) is on the managed side,
    and not in the C++ library?


    Mattias

    --
    Mattias Sjögren [C# MVP] mattias @ mvps.org
    http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
    Please reply only to the newsgroup.

    Comment

    • bbembi_de@lycos.de

      #3
      Re: Interop Memory Problem


      Mattias Sjögren schrieb:
      Are you sure the mempry leak (if there is one) is on the managed side,
      and not in the C++ library?
      The memory leak could be on the C++ side. That is a COM Server.
      But I just want to be sure the leak isn't in my C# application.

      bye bembi

      Comment

      Working...