C
Carlo
Hi,
I've a problem with a simple application and I don't know how to solve it.
Create a simple vb project, create a class with some member and one event,
add a timer with an interval of 10 ms. Every tick execute a "for" cycle for
many times (100 or even less), inside of it create an instance of the class
you have created and in the next line set it to "Nothing". Execute the
application and check the memory, you'll notice that memory grows more and
more. Now simply comment the line where the event is declared and memory
problems will disappears. How can be explained this behaviour? I've
converted the application in c# and the problem is not present. Starting the
application with a memory profiler a I've discovered that all memory is
occupied by "weak reference" object. This is a sample of the c# project:
public class TestClass
{
public string strName;
public bool bolCheck;
public delegate test_Handler (object sender,EventArgs args);
public xxx CheckMe;
}
.....in the tick part...
for (int i=0;i<100;i++)
{
TestClass objTestClass = new TestClass();
objTestClass = null;
}
In vb is the same, instead of declaring delegate i simple create an event:
Public Event CheckMe(sender as object, args as EventArgs)
The strange thing is that the same code written in c# works correctly, in
vb.net causes memory leak. Is there something connected with
the event keywork that i don't know?
Thank you very much for the answers.
Carlo
I've a problem with a simple application and I don't know how to solve it.
Create a simple vb project, create a class with some member and one event,
add a timer with an interval of 10 ms. Every tick execute a "for" cycle for
many times (100 or even less), inside of it create an instance of the class
you have created and in the next line set it to "Nothing". Execute the
application and check the memory, you'll notice that memory grows more and
more. Now simply comment the line where the event is declared and memory
problems will disappears. How can be explained this behaviour? I've
converted the application in c# and the problem is not present. Starting the
application with a memory profiler a I've discovered that all memory is
occupied by "weak reference" object. This is a sample of the c# project:
public class TestClass
{
public string strName;
public bool bolCheck;
public delegate test_Handler (object sender,EventArgs args);
public xxx CheckMe;
}
.....in the tick part...
for (int i=0;i<100;i++)
{
TestClass objTestClass = new TestClass();
objTestClass = null;
}
In vb is the same, instead of declaring delegate i simple create an event:
Public Event CheckMe(sender as object, args as EventArgs)
The strange thing is that the same code written in c# works correctly, in
vb.net causes memory leak. Is there something connected with
the event keywork that i don't know?
Thank you very much for the answers.
Carlo