Ok so I do have a question about implementing interfaces in a WinForms application. Basically I have a library of controls that I have built. Each control has an interface defined that interacts with the main form.
What I have been doing is creating a property handler that is the type of the interface and then doing it like this.
On the control:
public interface ITest {
void Test1();
void Test2();
}
private ITest _testHandler;
public ITest TestHandler {
get { return _testHandler; }
set { _testHandler = value; }
}
On the Main form:
public MainForm : Form, MyControl.ITest {
public MainForm() {
InitializeComponent();
MyTestControl.TestHandler = this;
}
// Implementing methods here...
}
The interface is working properly. I am just curious as to why it is taking up so much ram for each one. I don’t think that interfaces should really impact performance.
Interfaces don’t take up memory; data does. You’re implementation classes (among other things) are what are actually taking up the memory.
I would look for a memory profiler that would help you narrow down what’s taking up so much memory. It’s possible that you’e creating objects over and over again that aren’t necessary and could be improved with a Factory pattern that will cache objects that can be reused.
Viausl Studio (I think the Premium and Ultimate versions) have a Performance Wizard that includes memory analysis (under the Analyze menu in VS 2010 and 2012)
I have used Ants Memory Profiler and like it, but it’s not free. However it does have a 14-day free trial that mey get you over the hump.