InvokeMember memory leak .NET 2

B

Brian Stoop

Hi,

I have a console app that loads a DLL using Assembly.LoadFile.. Then it
calls a method in the DLL repeatedly in a loop like this:


while (true)
{
Thread.Sleep(10);

object [] par = new object[] {"xxx", "yyy"};

string val = (String)MyServer.MyDLLType.InvokeMember("GetMyValue",
BindingFlags.Default | BindingFlags.InvokeMethod, null, oMyInstance,
par);

}


But I can see the memory climbing ?

Does InvokeMember hold onto any memory, and if so is it possible to release
it ?


Thanks, Brian
 
P

Pavel Minaev

Hi,

I have a console app that loads a DLL using Assembly.LoadFile.. Then it
calls a method in the DLL repeatedly in a loop  like this:

while (true)
{
    Thread.Sleep(10);

     object [] par = new object[] {"xxx", "yyy"};

     string val =  (String)MyServer.MyDLLType.InvokeMember("GetMyValue",
BindingFlags.Default | BindingFlags.InvokeMethod, null,     oMyInstance,
par);

}

But I can see the memory climbing ?

Are you looking at it in Task Manager?

Most likely GC sees that you have plenty more available, and doesn't
bother to clean up the objects no longer in use. You can check that by
sticking a call to GC.Collect right after that InvokeMember.
Does InvokeMember hold onto any memory, and if so is it possible to release
it ?

It doesn't, but the implementation of your "GetMyValue" method
obviously might allocate resources that it doesn't release.
 
B

Brian Stoop

Thanks I'll investigate.

Hi,

I have a console app that loads a DLL using Assembly.LoadFile.. Then it
calls a method in the DLL repeatedly in a loop like this:

while (true)
{
Thread.Sleep(10);

object [] par = new object[] {"xxx", "yyy"};

string val = (String)MyServer.MyDLLType.InvokeMember("GetMyValue",
BindingFlags.Default | BindingFlags.InvokeMethod, null, oMyInstance,
par);

}

But I can see the memory climbing ?

Are you looking at it in Task Manager?

Most likely GC sees that you have plenty more available, and doesn't
bother to clean up the objects no longer in use. You can check that by
sticking a call to GC.Collect right after that InvokeMember.
Does InvokeMember hold onto any memory, and if so is it possible to
release
it ?

It doesn't, but the implementation of your "GetMyValue" method
obviously might allocate resources that it doesn't release.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top