Reply

Increasing memory consumption in SE

Hi, everyone!

 

Does anybody know why SE doesn't release memory when it finishes executing? I'm disposing all managed resources with Marshal.FinalReleaseComObject(obj), but it seems not to work. I also call GC.Collect() after the whole process.

 

It happens that SE closes when some users execute my add in for a couple of times, 6 or 7 maybe. I was wondering if it could be related to this increasing memory consumption.

 

Thanks in advance!

 

Before first execution

 

After 8th execution


2 REPLIES

Re: Increasing memory consumption in SE

Marcio,

 

Just to be clear, the fact that the edge.exe process is increasing in memory does not mean that Solid Edge is doing anything wrong or that there is an issue that they need to address. As an addin, you are loaded into their process space so any memory or handles that you leak will be reflected in the edge.exe process. This can happen in a native C++ addin or a .NET addin.

 

I also want to point out that memory not being freed does not necessarily mean that COM references are not being released. I can easily write an addin that will consume all available memory without touching COM.

 

Since you're working with .NET, there is a lot of .NET specific "things" that you need to understand. One is that .NET memory is not freed deterministically and is out of your control. The garbage collector manages .NET memory. You can GC.Collect() all day long but that is merely a suggestion, not a directive. I mention this because even in a standalone .NET application, you can watch the memory usage increase even though you've freed objects. At some point, the garbage collector will determine that enough is enough and will begin freeing memory. The only way to deterministically free .NET memory is to unload a AppDomain. Utilizing AppDomains is one technique that I demonstrate in my Samples for Solid Edge on CodePlex although I have not created an addin example using many AppDomains. I'll add it to my todo list for that project.

 

To help you determine what the root cause of your issue is, I offer this advice. My technique for solving these types of problems is process of elimination. Disable as much code as possible and start slowly adding back functionality until you can narrow down exactly what is causing the problem. Admittedly, this is not always possible but it's a place to start. It's hard for us to help because we don't have access to your code. If you can provide a reproducible sample for us to look at, that would be a start.

 

 

Jason Newell
Applications Architect
www.jasonnewell.net

Re: Increasing memory consumption in SE

Hi, Jason.

 

It's good to know that it's the common behavior of Solid Edge. That's what I wanted to know. Now I'll focus on your advice to try to discover what's causing the problem.

 

Unfortunatelly the add in is becomming a litle bit complex so it's difficult to send you a sample, but when I have some time I try build a smaller reproducible so that you can take a look at.

 

Thanks for you help!